diff --git a/exemples/sandbox.cpp b/examples/sandbox.cpp similarity index 100% rename from exemples/sandbox.cpp rename to examples/sandbox.cpp diff --git a/src/bakara/core/application.cpp b/src/bakara/core/application.cpp index c63f4e1..05cd5db 100644 --- a/src/bakara/core/application.cpp +++ b/src/bakara/core/application.cpp @@ -7,7 +7,9 @@ namespace Bk { { BK_CORE_MSG_ASSERT(p_instance == nullptr, "Application already exists, can not create two application.") Application::p_instance = this; - h_window = std::shared_ptr(Window::create_window()); + h_window = std::unique_ptr(Window::create_window()); + imgui_layer = new ImguiLayer(); + push_overlay(imgui_layer); h_window->set_event_callback(BK_BIND_EVENT_FN(on_event)); p_running = true; } @@ -48,6 +50,14 @@ namespace Bk { { while (p_running) { + for (Layer* layer : p_layer_stack) + layer->on_update(); + + imgui_layer->begin(); + for (Layer* layer : p_layer_stack) + layer->imgui_render(); + imgui_layer->end(); + h_window->on_update(); } } diff --git a/src/bakara/core/application.h b/src/bakara/core/application.h index dfa45bc..33c8f91 100644 --- a/src/bakara/core/application.h +++ b/src/bakara/core/application.h @@ -8,6 +8,7 @@ This file contains the main app abstraction. #include #include #include +#include namespace Bk { /*! \class Bk::Application @@ -67,12 +68,13 @@ namespace Bk { */ void run(); - std::shared_ptr get_window() { return std::shared_ptr(h_window); } + Window& get_window() { return *h_window; } static Application& get() { return *p_instance; } protected: - std::shared_ptr h_window; //!< Pointer to the main window + std::unique_ptr h_window; //!< Pointer to the main window + ImguiLayer* imgui_layer; /*! \fn Bk::Application::close Stops the application and the update loop without creating an event. diff --git a/src/bakara/core/layer.h b/src/bakara/core/layer.h index b6202cc..26841e4 100644 --- a/src/bakara/core/layer.h +++ b/src/bakara/core/layer.h @@ -13,6 +13,7 @@ namespace Bk { virtual void on_detach() {} virtual void on_event(Event& e) {} virtual void on_update() {} + virtual void imgui_render() {} const std::string to_string() const { return name; } protected: std::string name; diff --git a/src/bakara/imgui/imgui_layer.cpp b/src/bakara/imgui/imgui_layer.cpp index 7de732d..fd59e86 100644 --- a/src/bakara/imgui/imgui_layer.cpp +++ b/src/bakara/imgui/imgui_layer.cpp @@ -1,32 +1,80 @@ #include "imgui_layer.h" +#include "bakarapch.h" + +#include "bakara/core/application.h" + +#include +#include + +#include +#include + +#include +#include + namespace Bk { void ImguiLayer::on_attach() { + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); + io.IniFilename = NULL; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + //io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsClassic(); - Application& app = Application::get(); - GLFWwindow* window = static_cast(app.get_window()->get_native_window()); + // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. + ImGuiStyle& style = ImGui::GetStyle(); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + style.WindowRounding = 0.0f; + style.Colors[ImGuiCol_WindowBg].w = 1.0f; + } + Application& app = Application::get(); + GLFWwindow* window = static_cast(app.get_window().get_native_window()); + // Setup Platform/Renderer bindings ImGui_ImplGlfw_InitForOpenGL(window, true); - ImGui_ImplOpenGL3_Init("#version 410"); + ImGui_ImplOpenGL3_Init("#version 420"); } void ImguiLayer::on_detach() { - + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); } - void ImguiLayer::on_event(Bk::Event& e) + void ImguiLayer::begin() { - + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); } - void ImguiLayer::on_update() + void ImguiLayer::end() { + ImGuiIO& io = ImGui::GetIO(); + Application& app = Application::get(); + io.DisplaySize = ImVec2((float)app.get_window().get_width(), (float)app.get_window().get_height()); + + // Rendering + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + GLFWwindow* backup_current_context = glfwGetCurrentContext(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + glfwMakeContextCurrent(backup_current_context); + } } } \ No newline at end of file diff --git a/src/bakara/imgui/imgui_layer.h b/src/bakara/imgui/imgui_layer.h index 373674e..4c7f096 100644 --- a/src/bakara/imgui/imgui_layer.h +++ b/src/bakara/imgui/imgui_layer.h @@ -1,10 +1,7 @@ #pragma once #include -#include -#include -#include -#include +#include "bakara/core/layer.h" namespace Bk { class ImguiLayer : public Layer @@ -15,7 +12,7 @@ namespace Bk { void on_attach() override; void on_detach() override; - void on_event(Bk::Event& e) override; - void on_update() override; + void begin(); + void end(); }; } \ No newline at end of file diff --git a/src/platforms/glfw/glfw_window.cpp b/src/platforms/glfw/glfw_window.cpp index d1b5856..b2ab8be 100644 --- a/src/platforms/glfw/glfw_window.cpp +++ b/src/platforms/glfw/glfw_window.cpp @@ -1,4 +1,5 @@ #include +#include #include "glfw_window.h" namespace Bk { @@ -44,7 +45,11 @@ namespace Bk { int success = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); BK_CORE_MSG_ASSERT(success, "Couldn't load glad!") - BK_CORE_INFO("Opengl Raw Version : {0}",GL_VERSION); + GLint majVers = 0, minVers = 0; + glGetIntegerv(GL_MAJOR_VERSION, &majVers); + glGetIntegerv(GL_MINOR_VERSION, &minVers); + + BK_CORE_INFO("Opengl Version : {0}.{1}", majVers, minVers); glfwSetWindowUserPointer(p_window, &p_data); set_vsync(true);