Applying better design choices for general engine
Renderer is causing a big memory leak because it never deletes its Vertex Array
This commit is contained in:
64
Editor/src/UI/GUIRenderer.h
Normal file
64
Editor/src/UI/GUIRenderer.h
Normal file
@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <ImGuizmo.h>
|
||||
#include "../../src/YoggieEngine.h"
|
||||
|
||||
|
||||
class GUIRenderer {
|
||||
public:
|
||||
GUIRenderer(YoggieEngine::NativeWindow& window ) {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable;
|
||||
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18);
|
||||
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(window.GetGLFWHandle(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 440");
|
||||
}
|
||||
|
||||
void Begin ()
|
||||
{
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGuizmo::SetOrthographic(true);
|
||||
ImGuizmo::BeginFrame();
|
||||
|
||||
}
|
||||
|
||||
void End()
|
||||
{
|
||||
ImGui::EndFrame();
|
||||
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
GLFWwindow* last_context = glfwGetCurrentContext();
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
glfwMakeContextCurrent(last_context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
~GUIRenderer(){
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user