File tree Expand file tree Collapse file tree 4 files changed +23
-0
lines changed Expand file tree Collapse file tree 4 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ pub const Backend = enum {
1010 glfw ,
1111 sdl2_opengl3 ,
1212 osx_metal ,
13+ sdl2 ,
1314 sdl3_gpu ,
1415};
1516
@@ -386,6 +387,17 @@ pub fn build(b: *std.Build) void {
386387 .flags = objcflags ,
387388 });
388389 },
390+ .sdl2 = > {
391+ if (b .lazyDependency ("zsdl" , .{})) | zsdl | {
392+ imgui .addIncludePath (zsdl .path ("libs/sdl2/include" ));
393+ }
394+ imgui .addCSourceFiles (.{
395+ .files = &.{
396+ "libs/imgui/backends/imgui_impl_sdl2.cpp" ,
397+ },
398+ .flags = cflags ,
399+ });
400+ },
389401 .sdl3_gpu = > {
390402 if (b .lazyDependency ("zsdl" , .{})) | zsdl | {
391403 imgui .addIncludePath (zsdl .path ("libs/sdl3/include" ));
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ static const Uint32 SDL_WINDOW_VULKAN = 0x10000000;
138138extern " C" {
139139
140140bool ImGui_ImplSDL2_InitForOpenGL (SDL_Window* window, void * sdl_gl_context);
141+ bool ImGui_ImplSDL2_InitForOther (SDL_Window* window);
141142void ImGui_ImplSDL2_Shutdown ();
142143void ImGui_ImplSDL2_NewFrame ();
143144bool ImGui_ImplSDL2_ProcessEvent (const SDL_Event* event);
Original file line number Diff line number Diff line change 11const gui = @import ("gui.zig" );
22
3+ pub fn init (
4+ window : * const anyopaque , // SDL_Window
5+ ) void {
6+ if (! ImGui_ImplSDL2_InitForOther (window )) {
7+ unreachable ;
8+ }
9+ }
10+
311pub fn initOpenGL (
412 window : * const anyopaque , // SDL_Window
513 context : * const anyopaque , // SDL_GL_Context
@@ -24,6 +32,7 @@ pub fn newFrame() void {
2432}
2533
2634// These functions are defined in `imgui_impl_sdl2.cpp`
35+ extern fn ImGui_ImplSDL2_InitForOther (window : * const anyopaque ) bool ;
2736extern fn ImGui_ImplSDL2_InitForOpenGL (window : * const anyopaque , sdl_gl_context : * const anyopaque ) bool ;
2837extern fn ImGui_ImplSDL2_ProcessEvent (event : * const anyopaque ) bool ;
2938extern fn ImGui_ImplSDL2_NewFrame () void ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ pub const backend = switch (@import("zgui_options").backend) {
1818 .win32_dx12 = > @import ("backend_win32_dx12.zig" ),
1919 .sdl2_opengl3 = > @import ("backend_sdl2_opengl.zig" ),
2020 .osx_metal = > @import ("backend_osx_metal.zig" ),
21+ .sdl2 = > @import ("backend_sdl2.zig" ),
2122 .sdl3_gpu = > @import ("backend_sdl3_gpu.zig" ),
2223 .no_backend = > .{},
2324};
You can’t perform that action at this time.
0 commit comments