Add Imgui, Add TextureManager

From 1.1k texture loads to 5
This commit is contained in:
Bram Verhulst
2024-03-18 12:22:56 +01:00
parent 05f46b7eba
commit 39c744ba79
33 changed files with 59230 additions and 378 deletions

View File

@@ -1,3 +1,13 @@
#include "imgui/imgui.h"
#include "imgui/imgui_impl_sdl2.h"
#include "imgui/imgui_impl_opengl2.h"
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <SDL_opengles2.h>
#else
#include <SDL_opengl.h>
#endif
#include "base.h"
#include <iostream>
#include <algorithm>
@@ -88,6 +98,17 @@ void BaseGame::InitializeGameEngine()
// The viewport is the rectangular region of the window where the image is drawn.
glViewport(0, 0, int(m_Window.width), int(m_Window.height));
IMGUI_CHECKVERSION();
ImGui::CreateContext();
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
ImGui_ImplSDL2_InitForOpenGL(m_pWindow, m_pContext);
ImGui_ImplOpenGL2_Init();
// Set the Modelview matrix to the identity matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -147,6 +168,7 @@ void BaseGame::Run()
// Poll next event from queue
while (SDL_PollEvent(&e) != 0)
{
ImGui_ImplSDL2_ProcessEvent(&e);
// Handle the polled event
switch (e.type)
{
@@ -191,8 +213,18 @@ void BaseGame::Run()
// Call the BaseGame object 's Update function, using time in seconds (!)
this->Update(elapsedSeconds);
ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
this->ProcessImGui(); // Process the ImGui code in the game
ImGui::Render();
// Draw in the back buffer
this->Draw();
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
// Update screen: swap back and front buffer
SDL_GL_SwapWindow(m_pWindow);
@@ -202,6 +234,10 @@ void BaseGame::Run()
void BaseGame::CleanupGameEngine()
{
ImGui_ImplOpenGL2_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_GL_DeleteContext(m_pContext);
SDL_DestroyWindow(m_pWindow);