basic gui class setup but the demo window does not render

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 8f3524ae4e
commit f61c3c7c47

@ -35,6 +35,7 @@ set(LUNARIUM_SRC
"src/graphics/internalFont.cpp" "src/graphics/internalFont.cpp"
"src/input/keyboard.cpp" "src/input/keyboard.cpp"
"src/input/inputManager.cpp" "src/input/inputManager.cpp"
"src/graphics/gui/gui.cpp"
) )
# add the executable # add the executable

@ -12,12 +12,14 @@
// Sub Systems // Sub Systems
#include <window/window.h> #include <window/window.h>
#include <graphics/opengl/glGraphics.h> #include <graphics/opengl/glGraphics.h>
#include <graphics/gui/gui.h>
namespace lunarium namespace lunarium
{ {
Core* Core::mpInstance = nullptr; Core* Core::mpInstance = nullptr;
Core::Core() Core::Core()
: mbIsInit(false), mpArgs(nullptr), mpWindow(nullptr), mpGraphics(nullptr), mpInput(nullptr) : mbIsInit(false), mpArgs(nullptr), mpWindow(nullptr), mpGraphics(nullptr), mpInput(nullptr),
mGUI(GUI::GetInstance())
{ {
} }
@ -40,6 +42,9 @@ namespace lunarium
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!"); Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!");
// Shutdown subsystems // Shutdown subsystems
GUI::GetInstance().Shutdown();
GUI::FreeInstance();
mpInstance->mpInput->Shutdown(); mpInstance->mpInput->Shutdown();
delete mpInstance->mpInput; delete mpInstance->mpInput;
mpInstance->mpInput = nullptr; mpInstance->mpInput = nullptr;
@ -144,6 +149,9 @@ namespace lunarium
mpInput = new InputManager; mpInput = new InputManager;
mpInput->Initialize(mpWindow); mpInput->Initialize(mpWindow);
// GUI
mGUI.Initialize(mpWindow);
mbIsInit = true; mbIsInit = true;
} }
@ -196,8 +204,12 @@ namespace lunarium
// Update game state // Update game state
// Render // Render
mGUI.NewFrame();
mpGraphics->BeginDraw(); mpGraphics->BeginDraw();
// DEBUG: Render test ImGUI window
mGUI.ShowDemoWindow();
// DEBUG: Graphics tests // DEBUG: Graphics tests
mpGraphics->DrawFilledEllipse(glm::vec2(600, 300), glm::vec2(100, 150), Color(1.0f, 0.0f, 1.0f, 1.0f), 100); mpGraphics->DrawFilledEllipse(glm::vec2(600, 300), glm::vec2(100, 150), Color(1.0f, 0.0f, 1.0f, 1.0f), 100);
mpGraphics->DrawString("This is a test of the text renderer!", Rectangle(100, 200, width, 300), mpGraphics->DrawString("This is a test of the text renderer!", Rectangle(100, 200, width, 300),

@ -17,6 +17,7 @@
namespace lunarium namespace lunarium
{ {
class GUI;
class IGraphics; class IGraphics;
class Window; class Window;
@ -51,6 +52,7 @@ namespace lunarium
Window* mpWindow; Window* mpWindow;
IGraphics* mpGraphics; IGraphics* mpGraphics;
InputManager* mpInput; InputManager* mpInput;
GUI& mGUI;
InputManager::_KeyEvents mKeyEvents; InputManager::_KeyEvents mKeyEvents;

@ -0,0 +1,117 @@
/******************************************************************************
* File - gui.cpp
* Author - Joey Pollack
* Date - 2021/09/09 (y/m/d)
* Mod Date - 2021/09/09 (y/m/d)
* Description - The main class that manages Dear ImGui
******************************************************************************/
#include "gui.h"
#include <window/window.h>
#include <utils/helpers.h>
#include <utils/logger.h>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
namespace lunarium
{
GUI* GUI::mpInstance = nullptr;
GUI::GUI()
: mbIsInit(false), mbShowDemo(false)
{
}
GUI& GUI::GetInstance()
{
if (!mpInstance)
{
mpInstance = new GUI;
}
return *mpInstance;
}
void GUI::FreeInstance()
{
delete mpInstance;
mpInstance = nullptr;
}
OpRes GUI::Initialize(Window* pWindow)
{
if (mbIsInit)
{
return OpRes::Fail("GUI is already initialized!");
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
// Setup Dear ImGui style
ImGui::StyleColorsDark();
// 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;
}
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(pWindow->GetWindow(), true);
ImGui_ImplOpenGL3_Init(System::GetGLSLVersionString().c_str());
// Our state
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
mbShowDemo = true;
Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, "ImGui setup");
return OpRes::OK();
}
void GUI::Shutdown()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
mbIsInit = false;
}
void GUI::NewFrame()
{
if (!mbIsInit)
return;
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}
void GUI::ShowDemoWindow()
{
if (!mbIsInit)
return;
ImGui::ShowDemoWindow(&mbShowDemo);
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);
}
}
}

@ -0,0 +1,40 @@
/******************************************************************************
* File - gui.h
* Author - Joey Pollack
* Date - 2021/09/09 (y/m/d)
* Mod Date - 2021/09/09 (y/m/d)
* Description - The main class that manages Dear ImGui
******************************************************************************/
#ifndef GUI_H_
#define GUI_H_
#include <utils/opRes.h>
namespace lunarium
{
class Window;
class GUI
{
public:
static GUI& GetInstance();
static void FreeInstance();
OpRes Initialize(Window* pWindow);
void Shutdown();
void NewFrame();
void ShowDemoWindow();
private:
GUI();
GUI(const GUI&) = delete;
const GUI operator=(const GUI&) = delete;
private:
static GUI* mpInstance;
bool mbIsInit;
bool mbShowDemo;
};
}
#endif // GIU_H_

@ -7,7 +7,7 @@
#include <imgui_impl_opengl3.h> #include <imgui_impl_opengl3.h>
#include <pugixml.hpp> #include <pugixml.hpp>
#include "utils/logger.h" #include "utils/logger.h"
#include "utilsoOpRes.h" #include "utils/OpRes.h"
#include "core/state.h" #include "core/state.h"
#include "core/version.h" #include "core/version.h"
#include "utils/args.h" #include "utils/args.h"

Loading…
Cancel
Save