imgui working
parent
2c69e8d419
commit
2fb85dc9a2
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
git add *
|
||||||
|
git commit
|
||||||
|
git push -u origin main
|
|
@ -8,6 +8,9 @@
|
||||||
#include <blt/std/logging.h>
|
#include <blt/std/logging.h>
|
||||||
#include <blt/gfx/input.h>
|
#include <blt/gfx/input.h>
|
||||||
#include <queue>
|
#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)
|
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)
|
void init(const window_data& data)
|
||||||
{
|
{
|
||||||
/* -- Setup Error Callback -- */
|
/* -- Setup Error Callback -- */
|
||||||
|
@ -107,8 +134,13 @@ namespace blt::gfx
|
||||||
glfwSwapInterval(data.sync_interval);
|
glfwSwapInterval(data.sync_interval);
|
||||||
gladLoadGL(glfwGetProcAddress);
|
gladLoadGL(glfwGetProcAddress);
|
||||||
|
|
||||||
|
/* -- Setup our local callbacks, ImGUI will then call these -- */
|
||||||
create_callbacks();
|
create_callbacks();
|
||||||
|
|
||||||
|
/* -- Setup ImGUI -- */
|
||||||
|
setup_ImGUI();
|
||||||
|
|
||||||
|
|
||||||
/* -- Call User Provided post-window-init function -- */
|
/* -- Call User Provided post-window-init function -- */
|
||||||
data.init();
|
data.init();
|
||||||
|
|
||||||
|
@ -118,10 +150,21 @@ namespace blt::gfx
|
||||||
/* -- Get the current framebuffer size, update the global width/height state, along with OpenGL viewport -- */
|
/* -- 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);
|
glfwGetFramebufferSize(window_state.window, &window_state.width, &window_state.height);
|
||||||
glViewport(0, 0, 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 -- */
|
/* -- Call user update function -- */
|
||||||
data.update(window_state.width, window_state.height);
|
data.update(window_state.width, window_state.height);
|
||||||
|
|
||||||
|
/* -- Render the ImGUI frame -- */
|
||||||
|
ImGui::Render();
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
/* -- Update GLFW state -- */
|
/* -- Update GLFW state -- */
|
||||||
glfwSwapBuffers(window_state.window);
|
glfwSwapBuffers(window_state.window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
@ -130,6 +173,10 @@ namespace blt::gfx
|
||||||
|
|
||||||
void cleanup()
|
void cleanup()
|
||||||
{
|
{
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
glfwDestroyWindow(window_state.window);
|
glfwDestroyWindow(window_state.window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <blt/gfx/window.h>
|
#include <blt/gfx/window.h>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,7 @@ void init()
|
||||||
|
|
||||||
void update(std::int32_t width, std::int32_t height)
|
void update(std::int32_t width, std::int32_t height)
|
||||||
{
|
{
|
||||||
|
ImGui::ShowDemoWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
Loading…
Reference in New Issue