Compare commits
9 Commits
56bdb45491
...
d3110094f6
Author | SHA1 | Date |
---|---|---|
Rekai Nyangadzayi Musuka | d3110094f6 | |
Rekai Nyangadzayi Musuka | 42b225924a | |
Rekai Nyangadzayi Musuka | 1dfff5e0b0 | |
Rekai Nyangadzayi Musuka | 3e1017d4fc | |
Rekai Nyangadzayi Musuka | 0b90028b52 | |
Rekai Nyangadzayi Musuka | 70d7c0dc02 | |
Rekai Nyangadzayi Musuka | 55efe08bdf | |
Rekai Nyangadzayi Musuka | 78922b64ea | |
Rekai Nyangadzayi Musuka | b051d0c406 |
22
build.zig
22
build.zig
|
@ -105,6 +105,28 @@ pub fn package(
|
||||||
zgui_c_cpp.linkSystemLibraryName("dwmapi");
|
zgui_c_cpp.linkSystemLibraryName("dwmapi");
|
||||||
},
|
},
|
||||||
.sdl2_opengl3 => {
|
.sdl2_opengl3 => {
|
||||||
|
if (target.isWindows()) blk: {
|
||||||
|
// see: https://github.com/MasterQ32/SDL.zig/blob/37f4ba9e31bea895fa19ef8b90d1f51111e52e67/Sdk.zig#L182-L199
|
||||||
|
|
||||||
|
zgui_c_cpp.addVcpkgPaths(if (args.options.shared) .dynamic else .static) catch break :blk;
|
||||||
|
|
||||||
|
const vcpkg_triplet = zgui_c_cpp.target.vcpkgTriplet(b.allocator, if (args.options.shared) .Dynamic else .Static) catch |e| {
|
||||||
|
std.debug.panic("failed to determing vcpkg triplet: {}", .{e});
|
||||||
|
};
|
||||||
|
defer b.allocator.free(vcpkg_triplet);
|
||||||
|
|
||||||
|
const include_path = b.pathJoin(&.{ b.vcpkg_root.found, "installed", vcpkg_triplet, "include", "SDL2" });
|
||||||
|
zgui_c_cpp.include_dirs.append(.{ .raw_path = include_path }) catch @panic("out of memory");
|
||||||
|
|
||||||
|
const bin_path = zgui_c_cpp.vcpkg_bin_path orelse @panic("vcpkg paths were found, so vcpkg_bin_path should be set ");
|
||||||
|
const dll_path = std.fs.path.join(b.allocator, &.{ bin_path, "SDL2.dll" }) catch @panic("out of memory");
|
||||||
|
|
||||||
|
std.fs.cwd().access(dll_path, .{}) catch break :blk;
|
||||||
|
b.installBinFile(dll_path, "SDL2.dll");
|
||||||
|
}
|
||||||
|
|
||||||
|
zgui_c_cpp.linkSystemLibrary("SDL2");
|
||||||
|
|
||||||
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_sdl.cpp", cflags);
|
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_sdl.cpp", cflags);
|
||||||
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_opengl3.cpp", cflags);
|
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_opengl3.cpp", cflags);
|
||||||
},
|
},
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
// SDL
|
// SDL
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_syswm.h>
|
#include <SDL_syswm.h>
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <TargetConditionals.h>
|
#include <TargetConditionals.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
const zgui = @import("gui.zig");
|
||||||
|
|
||||||
|
const SDL_GL_Context = *anyopaque;
|
||||||
|
|
||||||
|
pub fn init(window: *anyopaque, context: SDL_GL_Context, glsl_version: []const u8) void {
|
||||||
|
if (!ImGui_ImplSDL2_InitForOpenGL(window, context)) unreachable;
|
||||||
|
if (!ImGui_ImplOpenGL3_Init(glsl_version.ptr)) unreachable;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit() void {
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplSDL2_Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn newFrame(width: f32, height: f32) void {
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
ImGui_ImplSDL2_NewFrame();
|
||||||
|
|
||||||
|
zgui.io.setDisplaySize(width, height);
|
||||||
|
zgui.io.setDisplayFramebufferScale(1.0, 1.0);
|
||||||
|
|
||||||
|
zgui.newFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn draw() void {
|
||||||
|
zgui.render();
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(zgui.getDrawData());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn processEvent(event: *anyopaque) bool {
|
||||||
|
return ImGui_ImplSDL2_ProcessEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern fn ImGui_ImplSDL2_InitForOpenGL(window: *anyopaque, sdl_gl_context: SDL_GL_Context) bool;
|
||||||
|
extern fn ImGui_ImplSDL2_Shutdown() void;
|
||||||
|
extern fn ImGui_ImplSDL2_NewFrame() void;
|
||||||
|
extern fn ImGui_ImplSDL2_ProcessEvent(event: *anyopaque) bool;
|
||||||
|
|
||||||
|
extern fn ImGui_ImplOpenGL3_Init(glsl_version: [*]const u8) bool;
|
||||||
|
extern fn ImGui_ImplOpenGL3_Shutdown() void;
|
||||||
|
extern fn ImGui_ImplOpenGL3_NewFrame() void;
|
||||||
|
extern fn ImGui_ImplOpenGL3_RenderDrawData(draw_data: *anyopaque) void;
|
|
@ -9,7 +9,9 @@ pub const version = @import("std").SemanticVersion{ .major = 0, .minor = 9, .pat
|
||||||
pub usingnamespace @import("gui.zig");
|
pub usingnamespace @import("gui.zig");
|
||||||
pub const plot = @import("plot.zig");
|
pub const plot = @import("plot.zig");
|
||||||
pub const backend = switch (@import("zgui_options").backend) {
|
pub const backend = switch (@import("zgui_options").backend) {
|
||||||
.glfw_wgpu => @import("backend_glfw_wgpu.zig"),
|
|
||||||
.glfw_opengl3 => @import("backend_glfw_opengl3.zig"),
|
.glfw_opengl3 => @import("backend_glfw_opengl3.zig"),
|
||||||
.no_backend, .win32_dx12, .sdl2_opengl3 => @panic("unsupported backend"),
|
.sdl2_opengl3 => @import("backend_sdl2_opengl3.zig"),
|
||||||
|
.glfw_wgpu => @import("backend_glfw_wgpu.zig"),
|
||||||
|
.win32_dx12 => .{}, // TODO:
|
||||||
|
.no_backend => .{},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue