Merge branch 'sdl2-opengl3-backend' into fork

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-03-26 19:52:55 -05:00
commit 70d7c0dc02
4 changed files with 55 additions and 4 deletions

View File

@ -107,6 +107,7 @@ pub fn package(
.sdl2_opengl3 => {
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.linkSystemLibrary("SDL2");
},
.no_backend => {},
}

View File

@ -67,8 +67,14 @@
#include "imgui_impl_sdl.h"
// SDL
#include <SDL.h>
#include <SDL_syswm.h>
#if defined(__WIN32__)
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#else
#include <SDL.h>
#include <SDL_syswm.h>
#endif
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

View File

@ -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;

View File

@ -9,7 +9,9 @@ pub const version = @import("std").SemanticVersion{ .major = 0, .minor = 9, .pat
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"),
.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 => .{},
};