Minor adjustments

This commit is contained in:
jammy3855
2026-02-19 23:24:48 -06:00
parent 335ef09f52
commit 2cb5b7d19b
4 changed files with 35 additions and 32 deletions

View File

@@ -1,16 +0,0 @@
# SDLGPU3
This example is a little different from the others, because `cimgui` doesn't come with bindings for the SDLGPU3 backend out of the box. Instead, this example shows how to generate the necessary bindings during cmake's configure time, then add the compiled library as a target for your application to link to.
For the generation phase from cmake you need LuaJIT to be present.
## Building
From the build directory of your choice:
`cmake path_to_example_sdlgpu3`
and after
`make`

View File

@@ -7,7 +7,10 @@ include(FetchContent)
FetchContent_Declare(
sdl3
URL https://github.com/libsdl-org/SDL/releases/download/release-3.2.8/SDL3-3.2.8.tar.gz
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG release-3.4.0
#GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)

View File

@@ -0,0 +1,16 @@
# SDLRenderer3
This example takes from `example_sdlgpu3`. We need to generate bindings for SDLRenderer3 backend because they are not native to `cimgui`. Then you can add the compiled library for linking in your application.
For the generation phase from cmake you need LuaJIT to be present.
## Building
From the build directory of your choice:
`cmake path_to_example_sdlgpu3`
Then simply run:
`make`

View File

@@ -8,15 +8,16 @@
#include <cimgui.h>
#include <cimgui_impl.h>
#define igGetIO igGetIO_Nil
int main() {
// Setup SDL library
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
fprintf(stderr, "Failed to init video! %s", SDL_GetError());
return 1;
};
// Setup window and renderer
float main_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
SDL_Window* window = NULL;
@@ -30,18 +31,18 @@ int main() {
SDL_ShowWindow(window);
// Setup Dear ImGui context
//IMGUI_CHECKVERSION();
igCreateContext(NULL);
ImGuiIO* io = igGetIO(); (void)io;
io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
// Setup Dear ImGui style
igStyleColorsDark(NULL);
//igStyleColorsLight(NULL);
// Setup scaling
ImGuiStyle* style = igGetStyle();
ImGuiStyle_ScaleAllSizes(style, main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
ImGuiStyle_ScaleAllSizes(style, main_scale);
style->FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
io->ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
io->ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
@@ -49,7 +50,6 @@ int main() {
// Setup Platform/Renderer backends
ImGui_ImplSDL3_InitForSDLRenderer(window, renderer);
ImGui_ImplSDLRenderer3_Init(renderer);
// finish loading data
// Our state
bool show_demo_window = true;
@@ -87,7 +87,7 @@ int main() {
continue;
}
// Start the Dear ImGui frame
// Setup Dear ImGui frame
SDL_SetRenderDrawColorFloat(renderer, clear_color.x, clear_color.y, clear_color.z, clear_color.w);
SDL_RenderClear(renderer);
ImGui_ImplSDLRenderer3_NewFrame();