Elevate Engine 1
Loading...
Searching...
No Matches
ImGuiLayer.cpp
Go to the documentation of this file.
1#include "eepch.h"
2#include "ImGuiLayer.h"
3
4#include "imgui.h"
5#include "backends/imgui_impl_opengl3.h"
6#include "backends/imgui_impl_glfw.h"
7#include "backends/imgui_impl_opengl3.h"
8#include "ImGuizmo.h"
9
11
13#include <GLFW/glfw3.h>
14
16 : Layer("ImGuiLayer") { }
17
21
23{
24 // Setup Dear ImGui context
25 IMGUI_CHECKVERSION();
26 ImGui::CreateContext();
27 ImGuiIO& io = ImGui::GetIO(); (void)io;
28 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
29 io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
30 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
31 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
32
33 //io.ConfigViewportsNoAutoMerge = true;
34 //io.ConfigViewportsNoTaskBarIcon = true;
36
37 // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
38 ImGuiStyle& style = ImGui::GetStyle();
39 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
40 {
41 style.WindowRounding = 0.0f;
42 style.Colors[ImGuiCol_WindowBg].w = 1.0f;
43 }
44
46 GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow());
47
48 // Setup Platform/Renderer bindings#
49 ImGui_ImplGlfw_InitForOpenGL(window, true);
50 ImGui_ImplOpenGL3_Init(EE_SHADER_VERSION_HEADER);
51}
52
54{
55 ImGui_ImplOpenGL3_Shutdown();
56 ImGui_ImplGlfw_Shutdown();
57 ImGui::DestroyContext();
58}
59
63
65{
66 ImGui_ImplOpenGL3_NewFrame();
67 ImGui_ImplGlfw_NewFrame();
68}
69
71{
72 // ImGui
73 ImGui::NewFrame();
74 // ImGuizmo
75 ImGuizmo::BeginFrame();
76}
77
79{
80 ImGui::Render();
81}
82
84{
85 ImGuiIO& io = ImGui::GetIO();
87 io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight());
88
89 // Rendering
90 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
91 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
92 {
93 GLFWwindow* backup_current_context = glfwGetCurrentContext();
94 ImGui::UpdatePlatformWindows();
95 ImGui::RenderPlatformWindowsDefault();
96 glfwMakeContextCurrent(backup_current_context);
97 }
98}
99
101{
102 ImGui_ImplOpenGL3_Shutdown();
103 ImGui_ImplGlfw_Shutdown();
104 ImGui::DestroyContext();
105}
#define EE_SHADER_VERSION_HEADER
Definition Core.h:31
static Application & Get()
Definition Application.h:62
virtual void OnDetach() override
virtual void OnImGuiRender() override
virtual void OnAttach() override
virtual unsigned int GetWidth() const =0
virtual unsigned int GetHeight() const =0
virtual void * GetNativeWindow() const =0
void SetDarkTheme()