added imgui
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
#include "GL/gl.h"
|
||||
#include "WindowGlfw.hpp"
|
||||
#include "Debug.hpp"
|
||||
#include "imgui/imgui.h"
|
||||
#include "extern/imgui_impl_glfw.h"
|
||||
#include "extern/imgui_impl_opengl3.h"
|
||||
#include "PathHelper.hpp"
|
||||
|
||||
TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor, bool _vsync)
|
||||
: OpenGLRenderingBackend(_backgroundColor, _vsync, 0, false){ }
|
||||
@@ -16,6 +20,16 @@ TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor
|
||||
useseImGui = _useseImGui;
|
||||
}
|
||||
|
||||
TSE::GLFW::OpenGLRenderingBackend::~OpenGLRenderingBackend()
|
||||
{
|
||||
if(useseImGui)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
}
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::InitPreWindow()
|
||||
{
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, TSE_OPENGL_VERSION_MAJOR);
|
||||
@@ -62,6 +76,29 @@ bool TSE::GLFW::OpenGLRenderingBackend::InitPostWindow()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TSE::GLFW::OpenGLRenderingBackend::InitEnd()
|
||||
{
|
||||
if(useseImGui)
|
||||
{
|
||||
string imguiIniPath;
|
||||
GetAppDataPath(imguiIniPath);
|
||||
imguiIniPath += "/UI.cfg";
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
io.IniFilename = imguiIniPath.c_str();
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
WindowGlfw* wnd = static_cast<WindowGlfw*>(window);
|
||||
ImGui_ImplGlfw_InitForOpenGL(wnd->window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 130");
|
||||
|
||||
Debug::Log("ImGui:" + std::string(ImGui::GetVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::onResize(int width, int height)
|
||||
{
|
||||
glViewport(0,0,width, height);
|
||||
@@ -75,6 +112,22 @@ void TSE::GLFW::OpenGLRenderingBackend::onUpdate() const
|
||||
Debug::Log("OpenGL Error: " + std::to_string(error));
|
||||
}
|
||||
|
||||
if(useseImGui)
|
||||
{
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
|
||||
if(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
GLFWwindow* backup_current_context = glfwGetCurrentContext();
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
glfwMakeContextCurrent(backup_current_context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WindowGlfw* wnd = static_cast<WindowGlfw*>(window);
|
||||
glfwSwapBuffers(wnd->window);
|
||||
}
|
||||
@@ -84,6 +137,12 @@ void TSE::GLFW::OpenGLRenderingBackend::onClear() const
|
||||
//cameras
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
if(useseImGui)
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::onClearDepthBuffer() const
|
||||
|
||||
Reference in New Issue
Block a user