xo-imgui: ex4 refactor [wip]

This commit is contained in:
Roland Conybeare 2025-08-30 14:37:07 -04:00
commit b3ab4d2cf7
3 changed files with 47 additions and 0 deletions

View file

@ -1,11 +1,46 @@
/* imgui_ex4.cpp */
#include "xo/imgui/VulkanApp.hpp"
#include <backends/imgui_impl_sdl2.h>
#include <backends/imgui_impl_vulkan.h>
#include <iostream>
namespace {
ImDrawData *
imgui_draw_frame(ImGuiContext * imgui_cx)
{
// Start the Dear ImGui frame
ImGui_ImplVulkan_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
// Create a simple ImGui window
ImGui::Begin("Hello, Vulkan + SDL2!");
ImGui::Text("This is a minimal ImGui + Vulkan + SDL2 example!");
static float f = 0.0f;
static int counter = 0;
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
if (ImGui::Button("Button"))
++counter;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",
1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
// Rendering
ImGui::Render();
ImDrawData* draw_data = ImGui::GetDrawData();
return draw_data;
}
}
int main() {
VulkanApp app;
app.assign_imgui_draw_frame(imgui_draw_frame);
try {
app.run();
} catch (const std::exception& e) {

View file

@ -16,6 +16,9 @@ public:
public:
VulkanApp() = default;
/** set imgui draw function **/
void assign_imgui_draw_frame(ImguiDrawFn fn);
void run();
private:
@ -72,6 +75,9 @@ private:
uint32_t current_frame_ = 0;
uint32_t graphics_queue_family_ = 0;
bool quit_ = false;
/** draw imgui **/
ImguiDrawFn imgui_draw_frame_;
};
/* end VulkanApp.hpp */

View file

@ -8,6 +8,12 @@
constexpr std::size_t c_max_frames_in_flight = 2;
void
VulkanApp::assign_imgui_draw_frame(ImguiDrawFn fn)
{
this->imgui_draw_frame_ = std::move(fn);
}
void
VulkanApp::run() {
this->init_window();