|
2 | 2 | #include <SDL3/SDL_main.h> |
3 | 3 | #include <SDL3/SDL.h> |
4 | 4 |
|
| 5 | +#include "imgui/imgui.h" |
| 6 | +#include "imgui/backends/imgui_impl_sdl3.h" |
| 7 | +#include "imgui/backends/imgui_impl_sdlrenderer3.h" |
| 8 | + |
5 | 9 | struct ToolState { |
6 | 10 | SDL_Window* window; |
7 | 11 | SDL_Renderer* renderer; |
@@ -45,18 +49,48 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) { |
45 | 49 |
|
46 | 50 | SDL_SetRenderVSync(state->renderer, -1); // Enable VSync if available |
47 | 51 |
|
| 52 | + IMGUI_CHECKVERSION(); |
| 53 | + ImGui::CreateContext(); |
| 54 | + ImGuiIO& io = ImGui::GetIO(); |
| 55 | + |
| 56 | + ImGui::StyleColorsDark(); |
| 57 | + |
| 58 | + ImGui_ImplSDL3_InitForSDLRenderer(state->window, state->renderer); |
| 59 | + ImGui_ImplSDLRenderer3_Init(state->renderer); |
| 60 | + |
48 | 61 | return SDL_APP_CONTINUE; |
49 | 62 | } |
50 | 63 |
|
51 | 64 | SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) { |
| 65 | + |
| 66 | + ImGui_ImplSDL3_ProcessEvent(event); |
| 67 | + |
52 | 68 | if (event->type == SDL_EVENT_QUIT) { |
53 | 69 | return SDL_APP_SUCCESS; // Exit the application |
54 | 70 | } |
55 | 71 | return SDL_APP_CONTINUE; |
56 | 72 | } |
57 | 73 |
|
58 | 74 | SDL_AppResult SDL_AppIterate(void* appstate) { |
59 | | - return SDL_APP_CONTINUE; |
| 75 | + SDL_Renderer* renderer = ((ToolState*)appstate)->renderer; |
| 76 | + ImGuiIO& io = ImGui::GetIO(); |
| 77 | + static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); |
| 78 | + |
| 79 | + ImGui_ImplSDLRenderer3_NewFrame(); |
| 80 | + ImGui_ImplSDL3_NewFrame(); |
| 81 | + ImGui::NewFrame(); |
| 82 | + |
| 83 | + ImGui::ShowDemoWindow(); |
| 84 | + ImGui::Render(); |
| 85 | + SDL_SetRenderScale(renderer, io.DisplayFramebufferScale.x, |
| 86 | + io.DisplayFramebufferScale.y); |
| 87 | + SDL_SetRenderDrawColorFloat(renderer, clear_color.x, clear_color.y, |
| 88 | + clear_color.z, clear_color.w); |
| 89 | + SDL_RenderClear(renderer); |
| 90 | + ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), renderer); |
| 91 | + SDL_RenderPresent(renderer); |
| 92 | + |
| 93 | + return SDL_APP_CONTINUE; |
60 | 94 | } |
61 | 95 |
|
62 | 96 | void SDL_AppQuit(void* appstate, SDL_AppResult result) { |
|
0 commit comments