Framebuffer now takes a size parameter

Scene now fills entire scene/Game view widget
main
Nigel Barink 2022-11-11 19:30:54 +01:00
parent 628225af45
commit 3d3596a3b6
6 changed files with 38 additions and 24 deletions

View File

@ -4,6 +4,8 @@
#include "../../YoggieEngine/src/PerfCounter.h"
#include "../../YoggieEngine/src/Scene/Entity.h"
#include "Project/Project.h"
#include "AssetManagement/AssetManager.h"
class EditorRuntime : public ApplicationRuntime {
@ -12,8 +14,15 @@ public:
void Start() override
{
CurrentProject = std::make_shared<Project>("Random");
std::string path = (std::filesystem::current_path()).string();
CurrentProject.get()->setProjectDirectory(path);
framebuffer = new Framebuffer();
AssetManager::Init();
AssetManager::setAssetPath(CurrentProject.get()->GetProjectDirectory());
AssetManager::BuildAssetView();
framebuffer = new Framebuffer(800, 600);
// Create a level and load it as the current level
auto importer = ModelImporter();
@ -43,6 +52,7 @@ public:
void Update() override
{
}
void FixedUpdate() override

View File

@ -117,27 +117,18 @@ void SceneExplorer(entt::entity& selected, Scene& scene )
void Viewport(Framebuffer& framebuffer) {
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar ;
ImGui::Begin("Viewport", false, viewportWindowFlags);
ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)800,(float)600 });
ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()});
ImGuizmo::SetDrawlist();
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
ImGuizmo::Enable(true);
auto cam = glm::mat4(1.0f);
auto eye = glm::vec3(0.0f);
auto center = glm::vec3(0.0f);
auto up = glm::vec3(0.0f, 1.0f, 0.0f);
auto view = glm::lookAt(eye, center, up);
glm::mat4 projection = glm::perspective(glm::radians(90.0f), (800.0f / 600.0f), 0.001f, 100.0f);
auto transformMatrix = glm::mat4(1.0f);
ImGuizmo::Manipulate(glm::value_ptr(view), glm::value_ptr(projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(transformMatrix));
//ImGuizmo::SetDrawlist();
//ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
//ImGuizmo::Enable(true);
//ImGuizmo::Manipulate(glm::value_ptr(view), glm::value_ptr(projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(trans));
//ImGuizmo::Manipulate(glm::value_ptr(static_cam), glm::value_ptr(static_projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(trans));
ImGuizmo::ViewManipulate(glm::value_ptr(cam), 8.0f, ImVec2{ 0.0f,0.0f }, ImVec2{ 128.0f,128.0f }, 0x10101010);
ImGui::End();
}
@ -147,7 +138,7 @@ void GamePort(Framebuffer& framebuffer)
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar;
ImGui::Begin("Game", false, viewportWindowFlags);
ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)800, (float)600 });
ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), { ImGui::GetWindowWidth(), ImGui::GetWindowHeight() });
ImGui::End();

View File

@ -36,7 +36,6 @@ public:
double previous = glfwGetTime();
double lag = 0.0;
AssetManager::Init();
renderer->Prepare(activeRuntime.MainScene);
while (!mainWindow.WindowShouldClose())

View File

@ -2,7 +2,7 @@
#include "Framebuffer.h"
namespace YoggieEngine {
Framebuffer::Framebuffer()
Framebuffer::Framebuffer(int width, int height)
{
glGenFramebuffers(1, &Id);
glBindFramebuffer(GL_FRAMEBUFFER, Id);
@ -11,7 +11,7 @@ namespace YoggieEngine {
glGenTextures(1, &ColourAttachment);
glBindTexture(GL_TEXTURE_2D, ColourAttachment);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@ -26,7 +26,7 @@ namespace YoggieEngine {
glGenTextures(1, &DepthAttachment);
glBindTexture(GL_TEXTURE_2D, DepthAttachment);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, 800, 600, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, 0);

View File

@ -3,7 +3,7 @@ namespace YoggieEngine {
class Framebuffer {
public:
Framebuffer();
Framebuffer(int width,int height);
~Framebuffer();
GLuint GetId() { return Id; }

View File

@ -8,6 +8,20 @@ namespace YoggieEngine {
glm::vec3 Position = glm::vec3(0.0f);
glm::vec3 Rotation = glm::vec3(0.0f);
glm::vec3 Scale = glm::vec3(1.0f);
glm::mat4 GetTransformMatrix() {
glm::mat4 result = glm::mat4(1.0f);
glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), Rotation.x, glm::vec3(1.f, 0.f, 0.f));
rotate *= glm::rotate(glm::mat4(1.0f), Rotation.y, glm::vec3(0.f, 1.f, 0.f));
rotate *= glm::rotate(glm::mat4(1.0f), Rotation.z, glm::vec3(0.f, 0.f, 1.f));
result = rotate * glm::scale(glm::mat4(1.0f), Scale) * glm::translate(glm::mat4(1.0f), Position) ;
return result;
}
};
struct LightComponent {