From 84046e89be8951d4020efd3cb7f22a21d69741f0 Mon Sep 17 00:00:00 2001 From: IlyaShurupov Date: Tue, 19 Mar 2024 11:37:55 +0300 Subject: [PATCH] Graphics Example Stable --- Graphics/CMakeLists.txt | 2 +- Graphics/examples/Example.cpp | 11 +++++++++-- Graphics/private/Canvas.cpp | 2 +- Graphics/private/DebugGUI.cpp | 2 ++ Graphics/private/EventHandler.cpp | 5 +++++ Graphics/private/Window.cpp | 7 ++++--- Graphics/public/EventHandler.hpp | 2 +- Graphics/public/Graphics.hpp | 2 +- Graphics/public/InputCodes.hpp | 2 ++ Graphics/public/Window.hpp | 5 ++--- 10 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Graphics/CMakeLists.txt b/Graphics/CMakeLists.txt index 25ddd02..9794823 100644 --- a/Graphics/CMakeLists.txt +++ b/Graphics/CMakeLists.txt @@ -10,7 +10,7 @@ file(GLOB HEADERS "./public/*.hpp") add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) target_include_directories(${PROJECT_NAME} PUBLIC ./public/) target_include_directories(${PROJECT_NAME} PRIVATE ${BINDINGS_INCLUDE}) -target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Allocators) +target_link_libraries(${PROJECT_NAME} PUBLIC Math Allocators) target_link_libraries(${PROJECT_NAME} PRIVATE ${BINDINGS_LIBS}) ### -------------------------- Examples -------------------------- ### diff --git a/Graphics/examples/Example.cpp b/Graphics/examples/Example.cpp index c7d8ab6..deca845 100644 --- a/Graphics/examples/Example.cpp +++ b/Graphics/examples/Example.cpp @@ -1,5 +1,7 @@ #include "Window.hpp" +#include "Graphics.hpp" + #include "Timing.hpp" #include "imgui.h" @@ -16,15 +18,19 @@ int main() { int fps = 0; tp::Timer timer(1000); + auto window = tp::Window::createWindow(); + { - auto window = tp::Window::createWindow(800, 600, "Window 1"); + tp::Graphics graphics(window); if (window) { while (!window->shouldClose()) { window->processEvents(); + graphics.proc(); ImGui::Text("fps: %i", fps); + graphics.draw(); window->draw(); if (timer.isTimeout()) { @@ -37,8 +43,9 @@ int main() { } } - tp::Window::destroyWindow(window); } + tp::Window::destroyWindow(window); + testModule.deinitialize(); } diff --git a/Graphics/private/Canvas.cpp b/Graphics/private/Canvas.cpp index b502bfb..418454c 100644 --- a/Graphics/private/Canvas.cpp +++ b/Graphics/private/Canvas.cpp @@ -4,7 +4,7 @@ #define GLEW_STATIC #include -#include "WindowContext.hpp" +#include "Graphics.hpp" // -------- Canvas -------- // #define NANOVG_GL3_IMPLEMENTATION diff --git a/Graphics/private/DebugGUI.cpp b/Graphics/private/DebugGUI.cpp index 9142784..ca608e5 100644 --- a/Graphics/private/DebugGUI.cpp +++ b/Graphics/private/DebugGUI.cpp @@ -1,6 +1,8 @@ #include "Window.hpp" #include "WindowContext.hpp" +#include "Allocators.hpp" + #include "Graphics.hpp" // -------- Debug UI -------- // diff --git a/Graphics/private/EventHandler.cpp b/Graphics/private/EventHandler.cpp index 6bf8d5c..502895c 100644 --- a/Graphics/private/EventHandler.cpp +++ b/Graphics/private/EventHandler.cpp @@ -1,2 +1,7 @@ #include "EventHandler.hpp" + +using namespace tp; + +EventHandler::EventHandler() = default; +EventHandler::~EventHandler() = default; \ No newline at end of file diff --git a/Graphics/private/Window.cpp b/Graphics/private/Window.cpp index f52efda..9456ca9 100644 --- a/Graphics/private/Window.cpp +++ b/Graphics/private/Window.cpp @@ -1,5 +1,6 @@ #include "Window.hpp" #include "WindowContext.hpp" +#include "Allocators.hpp" // -------- OpenGL -------- // #include @@ -31,13 +32,13 @@ static void keyCallback(GLFWwindow* window, int key, int scancode, int action, i static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods); static void scrollCallback(GLFWwindow* window, double xOffset, double yOffset); -Window::Window(Vec2F size, const String& title) { +Window::Window(Vec2F size, const char* title) { mContext = new Context(); glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1); // Create a window and OpenGL context - mContext->window = glfwCreateWindow((int) size.x, (int) size.y, title.read(), nullptr, nullptr); + mContext->window = glfwCreateWindow((int) size.x, (int) size.y, title, nullptr, nullptr); if (!mContext->window) { printf("Failed to create GLFW window\n"); return; @@ -63,7 +64,7 @@ Window::~Window() { delete mContext; } -Window* Window::createWindow(Vec2F size, const String& title) { +Window* Window::createWindow(Vec2F size, const char* title) { HeapAllocGlobal::startIgnore(); static int count = 1; diff --git a/Graphics/public/EventHandler.hpp b/Graphics/public/EventHandler.hpp index 8de9853..38d5364 100644 --- a/Graphics/public/EventHandler.hpp +++ b/Graphics/public/EventHandler.hpp @@ -56,7 +56,7 @@ namespace tp { // Event posters has no access to any custom state and only report any changes in any way class EventHandler { public: - EventHandler() = default; + EventHandler(); ~EventHandler(); public: // Event Poster Interface diff --git a/Graphics/public/Graphics.hpp b/Graphics/public/Graphics.hpp index ab96873..e950471 100644 --- a/Graphics/public/Graphics.hpp +++ b/Graphics/public/Graphics.hpp @@ -63,7 +63,7 @@ namespace tp { }; class Graphics { - private: + public: explicit Graphics(Window* window) : mGui(window), mCanvas(window) {} void proc() { diff --git a/Graphics/public/InputCodes.hpp b/Graphics/public/InputCodes.hpp index a0fd296..889b151 100644 --- a/Graphics/public/InputCodes.hpp +++ b/Graphics/public/InputCodes.hpp @@ -1,6 +1,8 @@ #pragma once +#include "Environment.hpp" + namespace tp { enum class InputID : ualni { /* Printable keys */ diff --git a/Graphics/public/Window.hpp b/Graphics/public/Window.hpp index 6b6bd01..2815271 100644 --- a/Graphics/public/Window.hpp +++ b/Graphics/public/Window.hpp @@ -2,7 +2,6 @@ #include "Buffer.hpp" #include "EventHandler.hpp" -#include "Strings.hpp" namespace tp { @@ -12,11 +11,11 @@ namespace tp { class Context; private: - Window(Vec2F size, const String& title); + Window(Vec2F size, const char* title); ~Window(); public: - static Window* createWindow(Vec2F size = { 1000.f, 900.f }, const String& title = "Window"); + static Window* createWindow(Vec2F size = { 1000.f, 900.f }, const char* title = "Window"); static void destroyWindow(Window* window); public: