From 7ec13a7020d605b88d86ad693e2ed6a93a5b354d Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Wed, 17 May 2023 19:41:48 +0200 Subject: [PATCH] Adding more input handlers --- Editor/premake5.lua | 5 +++++ Editor/src/EditorLayer.h | 5 ++--- Tests/premake5.lua | 5 ++++- YoggieEngine/premake5.lua | 2 ++ YoggieEngine/src/Application.h | 10 ++++++--- YoggieEngine/src/Graphics/OpenglAPI.cpp | 30 ++++++++++++++++++++++++- YoggieEngine/src/Layer.h | 14 ++++++------ 7 files changed, 56 insertions(+), 15 deletions(-) diff --git a/Editor/premake5.lua b/Editor/premake5.lua index 953e34e..24736ee 100644 --- a/Editor/premake5.lua +++ b/Editor/premake5.lua @@ -10,6 +10,11 @@ links{ "nfd" } + + +targetdir "%{wks.location}/%{prj.name}/build/%{cfg.buildcfg}" +objdir "%{wks.location}/%{prj.name}/build/%{cfg.buildcfg}/intermediates/" + includedirs{ "../YoggieEngine/build/Debug", diff --git a/Editor/src/EditorLayer.h b/Editor/src/EditorLayer.h index 1d7bf8f..6b6194c 100644 --- a/Editor/src/EditorLayer.h +++ b/Editor/src/EditorLayer.h @@ -31,7 +31,7 @@ class EditorLayer : public Layer { public: - EditorLayer() : + EditorLayer() : Layer(), Logo("rsc/Yoggie.png"), inspector(Selected), @@ -123,7 +123,6 @@ public: bool OnKey(int key, int mode) override { if (SceneisFocused) { - spdlog::info("update camera!"); if (key == YOGGIE_KEY_UP) camera->Rotation.x += movement_speed; @@ -413,7 +412,7 @@ public: // spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); SceneisFocused = ImGui::IsWindowFocused() || ImGui::IsWindowHovered(); ImGui::Image((ImTextureID)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(), - ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()}); + ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()},ImVec2{1,1}, ImVec2{0,0}); diff --git a/Tests/premake5.lua b/Tests/premake5.lua index 7c44806..fd19316 100644 --- a/Tests/premake5.lua +++ b/Tests/premake5.lua @@ -1,7 +1,10 @@ project "EngineTests" kind "ConsoleApp" language "C++" - targetdir "bin/%{cfg.buildcfg}" + + + targetdir "%{wks.location}/%{prj.name}/build/%{cfg.buildcfg}" + objdir "%{wks.location}/%{prj.name}/build/%{cfg.buildcfg}/intermediates/" files{"**.h", "**.cpp"} diff --git a/YoggieEngine/premake5.lua b/YoggieEngine/premake5.lua index 78b7dd3..bdacb64 100644 --- a/YoggieEngine/premake5.lua +++ b/YoggieEngine/premake5.lua @@ -5,6 +5,8 @@ project "YoggieEngine" pchsource "src/YoggieEngine.cpp" + targetdir "%{wks.location}/%{prj.name}/build/%{cfg.buildcfg}" + objdir "%{wks.location}/%{prj.name}/build/%{cfg.buildcfg}/intermediates/" buildmessage "Building Yoggie Engine" disablewarnings{ "4099" -- Ignore the missing debug signals for GLFW warning diff --git a/YoggieEngine/src/Application.h b/YoggieEngine/src/Application.h index d32f2a8..939e24d 100644 --- a/YoggieEngine/src/Application.h +++ b/YoggieEngine/src/Application.h @@ -19,15 +19,19 @@ namespace YoggieEngine { void GuiEnd(); void PushLayer(Layer* layer); - + static Application& Get() { return *Application::instance; } static void HandleKey(GLFWwindow* window, int key, int scancode, int action, int mods); - - + static void HandleMouseButton(GLFWwindow* window, int button, int action, int mods); + static void HandleScroll(GLFWwindow* window, double xoffset, double yoffset); protected: std::string m_AppName; NativeWindow* appWindow; LayerStack AppLayerstack; + Layer* guiLayer; + static Application* instance ; + + friend class ImGuiLayer; }; diff --git a/YoggieEngine/src/Graphics/OpenglAPI.cpp b/YoggieEngine/src/Graphics/OpenglAPI.cpp index 2793b80..71097cd 100644 --- a/YoggieEngine/src/Graphics/OpenglAPI.cpp +++ b/YoggieEngine/src/Graphics/OpenglAPI.cpp @@ -1,11 +1,38 @@ #include #include "OpenglAPI.h" namespace YoggieEngine { + + GLenum glCheckError_(const char* file, int line) { + GLenum errorCode; + while ((errorCode = glGetError()) != GL_NO_ERROR) { + std::string error; + switch (errorCode) + { + case GL_INVALID_ENUM: error = "INVALID_ENUM"; break; + case GL_INVALID_VALUE: error = "INVALID_VALUE"; break; + case GL_INVALID_OPERATION: error = "INVALID_OPERATION"; break; + case GL_STACK_OVERFLOW: error = "STACK_OVERFLOW"; break; + case GL_STACK_UNDERFLOW: error = "STACK_UNDERFLOW"; break; + case GL_OUT_OF_MEMORY: error = "OUT_OF_MEMORY"; break; + case GL_INVALID_FRAMEBUFFER_OPERATION: error = "INVALID_FRAMEBUFFER_OPERATION"; break; + }; + spdlog::error("{0} | {1} ({2})", error, file, line); + } + return errorCode; + } + +#ifdef DEBUG +#define glCheckError() glCheckError_(__FILE__, __LINE__) +#else +#define glCheckError() +#endif + void OpenGLApi::DrawTriangles(Render3DComponent rc) { glBindVertexArray(rc.VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rc.IBO); glDrawElements(GL_TRIANGLES, static_cast (rc.mesh.elements.size()), GL_UNSIGNED_INT, 0); + glCheckError(); glBindVertexArray(0); } @@ -15,9 +42,10 @@ namespace YoggieEngine { glDepthMask(GL_FALSE); glBindTexture(GL_TEXTURE_CUBE_MAP, CubeTexture.getID()); - + //glCheckError(); // INVALID ENUM FOR SOME REASON glBindVertexArray(VertexAttributeObject); glDrawArrays(GL_TRIANGLES, 0, 36); + //glCheckError(); glBindVertexArray(0); glDepthMask(GL_TRUE); diff --git a/YoggieEngine/src/Layer.h b/YoggieEngine/src/Layer.h index e761056..4f11f98 100644 --- a/YoggieEngine/src/Layer.h +++ b/YoggieEngine/src/Layer.h @@ -6,10 +6,6 @@ public: ~Layer() { OnDestroy(); } Layer() { OnCreate(); } - Layer(const std::string name ) - : Name(name) {} - - virtual void OnUpdate(){} virtual void OnUI(){} @@ -18,6 +14,13 @@ public: return false; } + virtual bool OnMouseButton(int button, int action) { + return false; + } + + virtual bool OnScroll(int xoffset, int yoffset) { + return false; + } virtual void OnStartup(){} @@ -26,9 +29,6 @@ public: virtual void OnCreate() {} virtual void OnDestroy(){} -private: - - std::string Name; }; \ No newline at end of file