Framebuffer now takes a size parameter

Scene now fills entire scene/Game view widget
This commit is contained in:
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/PerfCounter.h"
#include "../../YoggieEngine/src/Scene/Entity.h" #include "../../YoggieEngine/src/Scene/Entity.h"
#include "Project/Project.h" #include "Project/Project.h"
#include "AssetManagement/AssetManager.h"
class EditorRuntime : public ApplicationRuntime { class EditorRuntime : public ApplicationRuntime {
@ -13,7 +15,14 @@ public:
{ {
CurrentProject = std::make_shared<Project>("Random"); CurrentProject = std::make_shared<Project>("Random");
framebuffer = new Framebuffer(); std::string path = (std::filesystem::current_path()).string();
CurrentProject.get()->setProjectDirectory(path);
AssetManager::Init();
AssetManager::setAssetPath(CurrentProject.get()->GetProjectDirectory());
AssetManager::BuildAssetView();
framebuffer = new Framebuffer(800, 600);
// Create a level and load it as the current level // Create a level and load it as the current level
auto importer = ModelImporter(); auto importer = ModelImporter();
@ -43,6 +52,7 @@ public:
void Update() override void Update() override
{ {
} }
void FixedUpdate() override void FixedUpdate() override

View File

@ -119,25 +119,16 @@ void Viewport(Framebuffer& framebuffer) {
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar ; unsigned int viewportWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar ;
ImGui::Begin("Viewport", false, viewportWindowFlags); ImGui::Begin("Viewport", false, viewportWindowFlags);
ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)800,(float)600 });
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::Manipulate(glm::value_ptr(static_cam), glm::value_ptr(static_projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(trans)); ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()});
ImGuizmo::ViewManipulate(glm::value_ptr(cam), 8.0f, ImVec2{ 0.0f,0.0f }, ImVec2{ 128.0f,128.0f }, 0x10101010);
//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));
ImGui::End(); ImGui::End();
} }
@ -147,7 +138,7 @@ void GamePort(Framebuffer& framebuffer)
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar; unsigned int viewportWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar;
ImGui::Begin("Game", false, viewportWindowFlags); 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(); ImGui::End();

View File

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

View File

@ -2,7 +2,7 @@
#include "Framebuffer.h" #include "Framebuffer.h"
namespace YoggieEngine { namespace YoggieEngine {
Framebuffer::Framebuffer() Framebuffer::Framebuffer(int width, int height)
{ {
glGenFramebuffers(1, &Id); glGenFramebuffers(1, &Id);
glBindFramebuffer(GL_FRAMEBUFFER, Id); glBindFramebuffer(GL_FRAMEBUFFER, Id);
@ -11,7 +11,7 @@ namespace YoggieEngine {
glGenTextures(1, &ColourAttachment); glGenTextures(1, &ColourAttachment);
glBindTexture(GL_TEXTURE_2D, 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_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@ -26,7 +26,7 @@ namespace YoggieEngine {
glGenTextures(1, &DepthAttachment); glGenTextures(1, &DepthAttachment);
glBindTexture(GL_TEXTURE_2D, 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); glBindTexture(GL_TEXTURE_2D, 0);

View File

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

View File

@ -8,6 +8,20 @@ namespace YoggieEngine {
glm::vec3 Position = glm::vec3(0.0f); glm::vec3 Position = glm::vec3(0.0f);
glm::vec3 Rotation = glm::vec3(0.0f); glm::vec3 Rotation = glm::vec3(0.0f);
glm::vec3 Scale = glm::vec3(1.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 { struct LightComponent {