Skip to content

Commit 8d29cf7

Browse files
committed
Implement imgui
1 parent e1b144a commit 8d29cf7

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
99
project ("EncounterMaster" C CXX)
1010

1111
# Add source to this project's executable.
12-
add_executable (EncounterMaster "EncounterMaster.cpp" )
12+
add_executable (EncounterMaster "EncounterMaster.cpp" "imgui/imgui.cpp" "imgui/imgui_draw.cpp" "imgui/imgui_demo.cpp" "imgui/imgui_tables.cpp" "imgui/imgui_widgets.cpp" "imgui/backends/imgui_impl_sdlrenderer3.cpp" "imgui/backends/imgui_impl_sdl3.cpp")
1313

1414
# VCPKG configuration (wouldn't work without manually setting it sorry)
1515
set(CMAKE_TOOLCHAIN_FILE "E:/vcpkg/scripts/buildsystems/vcpkg.cmake")

EncounterMaster.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#include <SDL3/SDL_main.h>
33
#include <SDL3/SDL.h>
44

5+
#include "imgui/imgui.h"
6+
#include "imgui/backends/imgui_impl_sdl3.h"
7+
#include "imgui/backends/imgui_impl_sdlrenderer3.h"
8+
59
struct ToolState {
610
SDL_Window* window;
711
SDL_Renderer* renderer;
@@ -45,18 +49,48 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
4549

4650
SDL_SetRenderVSync(state->renderer, -1); // Enable VSync if available
4751

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+
4861
return SDL_APP_CONTINUE;
4962
}
5063

5164
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
65+
66+
ImGui_ImplSDL3_ProcessEvent(event);
67+
5268
if (event->type == SDL_EVENT_QUIT) {
5369
return SDL_APP_SUCCESS; // Exit the application
5470
}
5571
return SDL_APP_CONTINUE;
5672
}
5773

5874
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;
6094
}
6195

6296
void SDL_AppQuit(void* appstate, SDL_AppResult result) {

0 commit comments

Comments
 (0)