feat: add backend impl for glfw+opengl3

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-12-31 00:47:48 -06:00
parent 6c56505fa6
commit c7d1c329a1
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,38 @@
const zgui = @import("gui.zig");
pub fn init(window: *anyopaque, glsl_version: []const u8) void {
if (!ImGui_ImplGlfw_InitForOpenGL(window, true)) unreachable;
if (!ImGui_ImplOpenGL3_Init(glsl_version.ptr)) unreachable;
}
pub fn deinit() void {
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
}
pub fn newFrame(width: f32, height: f32) void {
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
zgui.io.setDisplaySize(width, height);
zgui.io.setDisplayFramebufferScale(1.0, 1.0);
zgui.newFrame();
}
pub fn render() void {
zgui.render();
}
pub fn draw() void {
ImGui_ImplOpenGL3_RenderDrawData(zgui.getDrawData());
}
extern fn ImGui_ImplGlfw_InitForOpenGL(window: *anyopaque, install_callbacks: bool) bool;
extern fn ImGui_ImplGlfw_Shutdown() void;
extern fn ImGui_ImplGlfw_NewFrame() void;
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; // ImDrawData

View File

@ -10,6 +10,7 @@ pub usingnamespace @import("gui.zig");
pub const plot = @import("plot.zig");
pub const backend = switch (@import("zgui_options").backend) {
.glfw_wgpu => @import("backend_glfw_wgpu.zig"),
.glfw_opengl3 => @import("backend_glfw_opengl3.zig"),
.win32_dx12 => .{}, // TODO:
.no_backend => .{},
};