imgui working

main
Brett 2023-12-16 01:32:25 -05:00
parent 2c69e8d419
commit 2fb85dc9a2
3 changed files with 53 additions and 1 deletions

4
commit.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
git add *
git commit
git push -u origin main

View File

@ -8,6 +8,9 @@
#include <blt/std/logging.h>
#include <blt/gfx/input.h>
#include <queue>
#include <imgui.h>
#include "backends/imgui_impl_opengl3.h"
#include "backends/imgui_impl_glfw.h"
void error_callback(int error, const char* description)
{
@ -86,6 +89,30 @@ namespace blt::gfx
});
}
void setup_ImGUI()
{
const char* glsl_version = "#version 100";
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window_state.window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
#ifdef __EMSCRIPTEN__
io.IniFilename = nullptr;
#endif
}
void init(const window_data& data)
{
/* -- Setup Error Callback -- */
@ -107,8 +134,13 @@ namespace blt::gfx
glfwSwapInterval(data.sync_interval);
gladLoadGL(glfwGetProcAddress);
/* -- Setup our local callbacks, ImGUI will then call these -- */
create_callbacks();
/* -- Setup ImGUI -- */
setup_ImGUI();
/* -- Call User Provided post-window-init function -- */
data.init();
@ -118,10 +150,21 @@ namespace blt::gfx
/* -- Get the current framebuffer size, update the global width/height state, along with OpenGL viewport -- */
glfwGetFramebufferSize(window_state.window, &window_state.width, &window_state.height);
glViewport(0, 0, window_state.width, window_state.height);
// TODO: user option for this
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* -- Begin the next ImGUI frame -- */
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
/* -- Call user update function -- */
data.update(window_state.width, window_state.height);
/* -- Render the ImGUI frame -- */
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
/* -- Update GLFW state -- */
glfwSwapBuffers(window_state.window);
glfwPollEvents();
@ -130,6 +173,10 @@ namespace blt::gfx
void cleanup()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window_state.window);
glfwTerminate();
}

View File

@ -1,6 +1,7 @@
#include <iostream>
#include <blt/gfx/window.h>
#include <imgui.h>
void init()
{
@ -9,7 +10,7 @@ void init()
void update(std::int32_t width, std::int32_t height)
{
ImGui::ShowDemoWindow();
}
int main()