Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub const Backend = enum {
glfw,
sdl2_opengl3,
osx_metal,
sdl2,
};

pub fn build(b: *std.Build) void {
Expand Down Expand Up @@ -385,6 +386,17 @@ pub fn build(b: *std.Build) void {
.flags = objcflags,
});
},
.sdl2 => {
if (b.lazyDependency("zsdl", .{})) |zsdl| {
imgui.addIncludePath(zsdl.path("libs/sdl2/include"));
}
imgui.addCSourceFiles(.{
.files = &.{
"libs/imgui/backends/imgui_impl_sdl2.cpp",
},
.flags = cflags,
});
},
.no_backend => {},
}

Expand Down
1 change: 1 addition & 0 deletions libs/imgui/backends/imgui_impl_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ static const Uint32 SDL_WINDOW_VULKAN = 0x10000000;
extern "C" {

bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
bool ImGui_ImplSDL2_InitForOther(SDL_Window* window);
void ImGui_ImplSDL2_Shutdown();
void ImGui_ImplSDL2_NewFrame();
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
Expand Down
9 changes: 9 additions & 0 deletions src/backend_sdl2.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const gui = @import("gui.zig");

pub fn init(
window: *const anyopaque, // SDL_Window
) void {
if (!ImGui_ImplSDL2_InitForOther(window)) {
unreachable;
}
}

pub fn initOpenGL(
window: *const anyopaque, // SDL_Window
context: *const anyopaque, // SDL_GL_Context
Expand All @@ -24,6 +32,7 @@ pub fn newFrame() void {
}

// These functions are defined in `imgui_impl_sdl2.cpp`
extern fn ImGui_ImplSDL2_InitForOther(window: *const anyopaque) bool;
extern fn ImGui_ImplSDL2_InitForOpenGL(window: *const anyopaque, sdl_gl_context: *const anyopaque) bool;
extern fn ImGui_ImplSDL2_ProcessEvent(event: *const anyopaque) bool;
extern fn ImGui_ImplSDL2_NewFrame() void;
Expand Down
1 change: 1 addition & 0 deletions src/gui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub const backend = switch (@import("zgui_options").backend) {
.win32_dx12 => @import("backend_win32_dx12.zig"),
.sdl2_opengl3 => @import("backend_sdl2_opengl.zig"),
.osx_metal => @import("backend_osx_metal.zig"),
.sdl2 => @import("backend_sdl2.zig"),
.no_backend => .{},
};
const te_enabled = @import("zgui_options").with_te;
Expand Down
Loading