From 7a229736d61ceda807a02a264df57e86a3ebb25c Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 21 Oct 2019 13:25:07 +0200 Subject: first working render! --- src/debug_gl.zig | 16 ++++++++++++++++ src/gl3_impl.zig | 1 + src/glfw_impl.zig | 41 +++++++++++++++++++++++++++++++++++++---- src/main.zig | 4 ++-- 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 src/debug_gl.zig (limited to 'src') diff --git a/src/debug_gl.zig b/src/debug_gl.zig new file mode 100644 index 0000000..debf51d --- /dev/null +++ b/src/debug_gl.zig @@ -0,0 +1,16 @@ +const c = @import("c.zig"); +const std = @import("std"); +const os = std.os; +const panic = std.debug.panic; +const builtin = @import("builtin"); + +pub const is_on = if (builtin.mode == builtin.Mode.ReleaseFast) c.GL_FALSE else c.GL_TRUE; + +pub fn assertNoError() void { + if (builtin.mode != builtin.Mode.ReleaseFast) { + const err = c.glGetError(); + if (err != c.GL_NO_ERROR) { + panic("GL error: {}\n", err); + } + } +} diff --git a/src/gl3_impl.zig b/src/gl3_impl.zig index 0d88621..70a60b5 100644 --- a/src/gl3_impl.zig +++ b/src/gl3_impl.zig @@ -423,6 +423,7 @@ fn SetupRenderState(draw_data: *c.ImDrawData, fb_width: i32, fb_height: i32, ver [_]f32{ 0.0, 0.0, -1.0, 0.0 }, [_]f32{ (R+L)/(L-R), (T+B)/(B-T), 0.0, 1.0 }, }; + c.glUseProgram(g_ShaderHandle); c.glUniform1i(g_AttribLocationTex, 0); c.glUniformMatrix4fv(g_AttribLocationProjMtx, 1, c.GL_FALSE, &ortho_projection[0][0]); if (@hasField(c, "GL_SAMPLER_BINDING")) diff --git a/src/glfw_impl.zig b/src/glfw_impl.zig index 8bfbec2..dffd7bf 100644 --- a/src/glfw_impl.zig +++ b/src/glfw_impl.zig @@ -4,9 +4,9 @@ const debug = @import("std").debug; const math = @import("std").math; pub const ClientApi = enum { - Unknown, - OpenGL, - Vulkan, + Unknown, + OpenGL, + Vulkan, }; // Data @@ -145,7 +145,40 @@ pub fn NewFrame() void { } fn UpdateMonitors() void { - // @TODO + const platform_io = c.igGetPlatformIO(); + var monitors_count : c_int = 0; + const glfw_monitors = c.glfwGetMonitors(&monitors_count)[0..@intCast(usize, monitors_count)]; + + c.ImVector_ImGuiPlatformMonitor_Resize(&platform_io.*.Monitors, monitors_count); + for (glfw_monitors) |glfw_monitor, n| { + var monitor = &platform_io.*.Monitors.Data[n]; + var x : c_int = undefined; + var y : c_int = undefined; + c.glfwGetMonitorPos(glfw_monitor, &x, &y); + const vid_mode = c.glfwGetVideoMode(glfw_monitor); // glfw_monitors[n]); + + monitor.*.MainPos = c.ImVec2{ .x = @intToFloat(f32, x), .y = @intToFloat(f32, y) }; + monitor.*.MainSize = c.ImVec2{ + .x = @intToFloat(f32, vid_mode.*.width), + .y = @intToFloat(f32, vid_mode.*.height), + }; + if (false and c.GLFW_HAS_MONITOR_WORK_AREA) { + var w : c_int = undefined; + var h : c_int = undefined; + c.glfwGetMonitorWorkarea(glfw_monitor, &x, &y, &w, &h); + monitor.*.WorkPos = ImVec2{ .x = @intToFloat(f32, x), .y = @intToFloat(f32, y) }; + monitor.*.WorkSize = ImVec2{ .x = @intToFloat(f32, w), .y = @intToFloat(f32, h) }; + } + if (false and c.GLFW_HAS_PER_MONITOR_DPI) { + // Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, + // which generally needs to be set in the manifest or at runtime. + var x_scale : f32 = undefined; + var y_scale : f32 = undefined; + c.glfwGetMonitorContentScale(glfw_monitor, &x_scale, &y_scale); + monitor.*.DpiScale = x_scale; + } + } + g_WantUpdateMonitors = false; } fn UpdateMousePosAndButtons() void { diff --git a/src/main.zig b/src/main.zig index 882faf0..5d5f24a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,7 @@ const c = @import("c.zig"); const std = @import("std"); const panic = std.debug.panic; +const debug_gl = @import("debug_gl.zig"); const glfw_impl = @import("glfw_impl.zig"); const gl3_impl = @import("gl3_impl.zig"); @@ -21,9 +22,8 @@ pub fn main() !void { c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MAJOR, 3); c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MINOR, 2); c.glfwWindowHint(c.GLFW_OPENGL_FORWARD_COMPAT, c.GL_TRUE); + c.glfwWindowHint(c.GLFW_OPENGL_DEBUG_CONTEXT, debug_gl.is_on); c.glfwWindowHint(c.GLFW_OPENGL_PROFILE, c.GLFW_OPENGL_CORE_PROFILE); - - // c.glfwWindowHint(c.GLFW_OPENGL_DEBUG_CONTEXT, debug_gl.is_on); // c.glfwWindowHint(c.GLFW_DEPTH_BITS, 0); // c.glfwWindowHint(c.GLFW_STENCIL_BITS, 8); c.glfwWindowHint(c.GLFW_RESIZABLE, c.GL_TRUE); -- cgit v1.2.3