parent
5959834aca
commit
b61777f5d7
7 changed files with 80 additions and 17 deletions
@ -1,32 +1,80 @@ |
||||
#include "imgui_layer.h" |
||||
|
||||
#include "bakarapch.h" |
||||
|
||||
#include "bakara/core/application.h" |
||||
|
||||
#include <imgui.h> |
||||
#include <imgui_internal.h> |
||||
|
||||
#include <backends/imgui_impl_glfw.h> |
||||
#include <backends/imgui_impl_opengl3.h> |
||||
|
||||
#include <GLFW/glfw3.h> |
||||
#include <glad/glad.h> |
||||
|
||||
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<GLFWwindow*>(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<GLFWwindow*>(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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in New Issue