summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/c.zig1
-rw-r--r--src/gl3_impl.zig60
-rw-r--r--src/glfw_impl.zig94
-rw-r--r--src/main.zig20
4 files changed, 90 insertions, 85 deletions
diff --git a/src/c.zig b/src/c.zig
index 54782ef..1f1b5e0 100644
--- a/src/c.zig
+++ b/src/c.zig
@@ -3,4 +3,5 @@ pub usingnamespace @cImport({
@cDefine("CIMGUI_DEFINE_ENUMS_AND_STRUCTS", "1");
@cInclude("cimgui.h");
@cInclude("GLFW/glfw3.h");
+ @cInclude("lo/lo.h");
});
diff --git a/src/gl3_impl.zig b/src/gl3_impl.zig
index b056056..27212ff 100644
--- a/src/gl3_impl.zig
+++ b/src/gl3_impl.zig
@@ -26,7 +26,7 @@ var g_ElementsHandle: c.GLuint = 0;
pub fn Init() void {
const io = c.igGetIO();
- io.*.BackendRendererName = c"imgui_impl_gl3.zig";
+ io.*.BackendRendererName = "imgui_impl_gl3.zig";
if (OpenGLHasDrawWithBaseVertex)
io.*.BackendFlags |= @enumToInt(c.ImGuiBackendFlags_RendererHasVtxOffset);
// @TODO: Viewports
@@ -74,31 +74,31 @@ fn CreateDeviceObjects() !void {
// @TODO: GLSL versions?
const vertex_shader_glsl: [*]const c.GLchar =
- c\\#version 150
- c\\uniform mat4 ProjMtx;
- c\\in vec2 Position;
- c\\in vec2 UV;
- c\\in vec4 Color;
- c\\out vec2 Frag_UV;
- c\\out vec4 Frag_Color;
- c\\void main()
- c\\{
- c\\ Frag_UV = UV;
- c\\ Frag_Color = Color;
- c\\ gl_Position = ProjMtx * vec4(Position.xy, 0, 1);
- c\\}
+ \\#version 150
+ \\uniform mat4 ProjMtx;
+ \\in vec2 Position;
+ \\in vec2 UV;
+ \\in vec4 Color;
+ \\out vec2 Frag_UV;
+ \\out vec4 Frag_Color;
+ \\void main()
+ \\{
+ \\ Frag_UV = UV;
+ \\ Frag_Color = Color;
+ \\ gl_Position = ProjMtx * vec4(Position.xy, 0, 1);
+ \\}
;
const fragment_shader_glsl: [*]const c.GLchar =
- c\\#version 150
- c\\uniform sampler2D Texture;
- c\\in vec2 Frag_UV;
- c\\in vec4 Frag_Color;
- c\\out vec4 Out_Color;
- c\\void main()
- c\\{
- c\\ Out_Color = Frag_Color * texture(Texture, Frag_UV.st);
- c\\}
+ \\#version 150
+ \\uniform sampler2D Texture;
+ \\in vec2 Frag_UV;
+ \\in vec4 Frag_Color;
+ \\out vec4 Out_Color;
+ \\void main()
+ \\{
+ \\ Out_Color = Frag_Color * texture(Texture, Frag_UV.st);
+ \\}
;
// Create shaders / programs
@@ -118,11 +118,11 @@ fn CreateDeviceObjects() !void {
c.glLinkProgram(g_ShaderHandle);
try CheckThing(.Program, g_ShaderHandle, "shader program");
- g_AttribLocationTex = c.glGetUniformLocation(g_ShaderHandle, c"Texture");
- g_AttribLocationProjMtx = c.glGetUniformLocation(g_ShaderHandle, c"ProjMtx");
- g_AttribLocationVtxPos = c.glGetAttribLocation(g_ShaderHandle, c"Position");
- g_AttribLocationVtxUV = c.glGetAttribLocation(g_ShaderHandle, c"UV");
- g_AttribLocationVtxColor = c.glGetAttribLocation(g_ShaderHandle, c"Color");
+ g_AttribLocationTex = c.glGetUniformLocation(g_ShaderHandle, "Texture");
+ g_AttribLocationProjMtx = c.glGetUniformLocation(g_ShaderHandle, "ProjMtx");
+ g_AttribLocationVtxPos = c.glGetAttribLocation(g_ShaderHandle, "Position");
+ g_AttribLocationVtxUV = c.glGetAttribLocation(g_ShaderHandle, "UV");
+ g_AttribLocationVtxColor = c.glGetAttribLocation(g_ShaderHandle, "Color");
// Create buffers
c.glGenBuffers(1, &g_VboHandle);
@@ -155,11 +155,11 @@ fn CheckThing(comptime thingType: CheckableThing, handle: c.GLuint, desc: []cons
var buf: [1024]u8 = undefined;
var length: c.GLsizei = undefined;
getInfoLogFunc(handle, buf.len, &length, &buf[0]);
- debug.warn("{}\n", buf[0..@intCast(usize, length)]);
+ debug.warn("{}\n", .{buf[0..@intCast(usize, length)]});
}
if (@intCast(c.GLboolean, status) == c.GL_FALSE) {
- debug.warn("ERROR: CreateDeviceObjects: failed to compile/link {}! (with GLSL '{}')\n", desc, g_GlslVersionString);
+ debug.warn("ERROR: CreateDeviceObjects: failed to compile/link {}! (with GLSL '{}')\n", .{ desc, g_GlslVersionString });
return error.ShaderLinkError;
}
}
diff --git a/src/glfw_impl.zig b/src/glfw_impl.zig
index d2defa5..7d28e08 100644
--- a/src/glfw_impl.zig
+++ b/src/glfw_impl.zig
@@ -15,7 +15,7 @@ var g_Window: ?*c.GLFWwindow = null;
var g_ClientApi: ClientApi = .Unknown;
var g_Time: f64 = 0.0;
var g_MouseJustPressed = [_]bool{false} ** 5;
-var g_MouseCursors = [_]?*c.GLFWcursor{null} ** @enumToInt(c.ImGuiMouseCursor_COUNT);
+var g_MouseCursors = [_]?*c.GLFWcursor{null} ** c.ImGuiMouseCursor_COUNT;
var g_WantUpdateMonitors = true;
// Chain GLFW callbacks for main viewport:
@@ -31,51 +31,51 @@ pub fn Init(window: *c.GLFWwindow, install_callbacks: bool, client_api: ClientAp
// Setup back-end capabilities flags
const io = c.igGetIO();
- io.*.BackendFlags |= @enumToInt(c.ImGuiBackendFlags_HasMouseCursors); // We can honor GetMouseCursor() values (optional)
- io.*.BackendFlags |= @enumToInt(c.ImGuiBackendFlags_HasSetMousePos); // We can honor io.WantSetMousePos requests (optional, rarely used)
- if (false) io.*.BackendFlags |= @enumToInt(c.ImGuiBackendFlags_PlatformHasViewports); // We can create multi-viewports on the Platform side (optional)
+ io.*.BackendFlags |= c.ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
+ io.*.BackendFlags |= c.ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
+ if (false) io.*.BackendFlags |= c.ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
if (false and @hasField(c, "GLFW_HAS_GLFW_HOVERED") and builtin.os == builtin.Os.windows) {
- io.*.BackendFlags |= @enumToInt(ImGuiBackendFlags_HasMouseHoveredViewport); // We can set io.MouseHoveredViewport correctly (optional, not easy)
+ io.*.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can set io.MouseHoveredViewport correctly (optional, not easy)
}
- io.*.BackendPlatformName = c"imgui_impl_glfw.zig";
+ io.*.BackendPlatformName = "imgui_impl_glfw.zig";
// Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array.
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Tab)] = c.GLFW_KEY_TAB;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_LeftArrow)] = c.GLFW_KEY_LEFT;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_RightArrow)] = c.GLFW_KEY_RIGHT;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_UpArrow)] = c.GLFW_KEY_UP;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_DownArrow)] = c.GLFW_KEY_DOWN;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_PageUp)] = c.GLFW_KEY_PAGE_UP;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_PageDown)] = c.GLFW_KEY_PAGE_DOWN;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Home)] = c.GLFW_KEY_HOME;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_End)] = c.GLFW_KEY_END;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Insert)] = c.GLFW_KEY_INSERT;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Delete)] = c.GLFW_KEY_DELETE;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Backspace)] = c.GLFW_KEY_BACKSPACE;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Space)] = c.GLFW_KEY_SPACE;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Enter)] = c.GLFW_KEY_ENTER;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Escape)] = c.GLFW_KEY_ESCAPE;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_KeyPadEnter)] = c.GLFW_KEY_KP_ENTER;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_A)] = c.GLFW_KEY_A;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_C)] = c.GLFW_KEY_C;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_V)] = c.GLFW_KEY_V;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_X)] = c.GLFW_KEY_X;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Y)] = c.GLFW_KEY_Y;
- io.*.KeyMap[@enumToInt(c.ImGuiKey_Z)] = c.GLFW_KEY_Z;
+ io.*.KeyMap[c.ImGuiKey_Tab] = c.GLFW_KEY_TAB;
+ io.*.KeyMap[c.ImGuiKey_LeftArrow] = c.GLFW_KEY_LEFT;
+ io.*.KeyMap[c.ImGuiKey_RightArrow] = c.GLFW_KEY_RIGHT;
+ io.*.KeyMap[c.ImGuiKey_UpArrow] = c.GLFW_KEY_UP;
+ io.*.KeyMap[c.ImGuiKey_DownArrow] = c.GLFW_KEY_DOWN;
+ io.*.KeyMap[c.ImGuiKey_PageUp] = c.GLFW_KEY_PAGE_UP;
+ io.*.KeyMap[c.ImGuiKey_PageDown] = c.GLFW_KEY_PAGE_DOWN;
+ io.*.KeyMap[c.ImGuiKey_Home] = c.GLFW_KEY_HOME;
+ io.*.KeyMap[c.ImGuiKey_End] = c.GLFW_KEY_END;
+ io.*.KeyMap[c.ImGuiKey_Insert] = c.GLFW_KEY_INSERT;
+ io.*.KeyMap[c.ImGuiKey_Delete] = c.GLFW_KEY_DELETE;
+ io.*.KeyMap[c.ImGuiKey_Backspace] = c.GLFW_KEY_BACKSPACE;
+ io.*.KeyMap[c.ImGuiKey_Space] = c.GLFW_KEY_SPACE;
+ io.*.KeyMap[c.ImGuiKey_Enter] = c.GLFW_KEY_ENTER;
+ io.*.KeyMap[c.ImGuiKey_Escape] = c.GLFW_KEY_ESCAPE;
+ io.*.KeyMap[c.ImGuiKey_KeyPadEnter] = c.GLFW_KEY_KP_ENTER;
+ io.*.KeyMap[c.ImGuiKey_A] = c.GLFW_KEY_A;
+ io.*.KeyMap[c.ImGuiKey_C] = c.GLFW_KEY_C;
+ io.*.KeyMap[c.ImGuiKey_V] = c.GLFW_KEY_V;
+ io.*.KeyMap[c.ImGuiKey_X] = c.GLFW_KEY_X;
+ io.*.KeyMap[c.ImGuiKey_Y] = c.GLFW_KEY_Y;
+ io.*.KeyMap[c.ImGuiKey_Z] = c.GLFW_KEY_Z;
// @TODO: Clipboard
// io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
// io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
io.*.ClipboardUserData = g_Window;
- g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_Arrow)] = c.glfwCreateStandardCursor(c.GLFW_ARROW_CURSOR);
- g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_TextInput)] = c.glfwCreateStandardCursor(c.GLFW_IBEAM_CURSOR);
- g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_ResizeAll)] = c.glfwCreateStandardCursor(c.GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this.
- g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_ResizeNS)] = c.glfwCreateStandardCursor(c.GLFW_VRESIZE_CURSOR);
- g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_ResizeEW)] = c.glfwCreateStandardCursor(c.GLFW_HRESIZE_CURSOR);
- g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_ResizeNESW)] = c.glfwCreateStandardCursor(c.GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this.
- g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_ResizeNWSE)] = c.glfwCreateStandardCursor(c.GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this.
- g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_Hand)] = c.glfwCreateStandardCursor(c.GLFW_HAND_CURSOR);
+ g_MouseCursors[c.ImGuiMouseCursor_Arrow] = c.glfwCreateStandardCursor(c.GLFW_ARROW_CURSOR);
+ g_MouseCursors[c.ImGuiMouseCursor_TextInput] = c.glfwCreateStandardCursor(c.GLFW_IBEAM_CURSOR);
+ g_MouseCursors[c.ImGuiMouseCursor_ResizeAll] = c.glfwCreateStandardCursor(c.GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this.
+ g_MouseCursors[c.ImGuiMouseCursor_ResizeNS] = c.glfwCreateStandardCursor(c.GLFW_VRESIZE_CURSOR);
+ g_MouseCursors[c.ImGuiMouseCursor_ResizeEW] = c.glfwCreateStandardCursor(c.GLFW_HRESIZE_CURSOR);
+ g_MouseCursors[c.ImGuiMouseCursor_ResizeNESW] = c.glfwCreateStandardCursor(c.GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this.
+ g_MouseCursors[c.ImGuiMouseCursor_ResizeNWSE] = c.glfwCreateStandardCursor(c.GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this.
+ g_MouseCursors[c.ImGuiMouseCursor_Hand] = c.glfwCreateStandardCursor(c.GLFW_HAND_CURSOR);
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
g_PrevUserCallbackMousebutton = null;
@@ -92,11 +92,11 @@ pub fn Init(window: *c.GLFWwindow, install_callbacks: bool, client_api: ClientAp
// Our mouse update function expect PlatformHandle to be filled for the main viewport
const main_viewport = c.igGetMainViewport();
main_viewport.*.PlatformHandle = g_Window;
- if (builtin.os == builtin.Os.windows)
- main_viewport.*.PlatformHandleRaw = c.glfwGetWin32Window(g_Window);
+ // if (builtin.os == builtin.Os.windows)
+ // main_viewport.*.PlatformHandleRaw = c.glfwGetWin32Window(g_Window);
// @TODO: Platform Interface (Viewport)
- if (io.*.ConfigFlags & @enumToInt(c.ImGuiConfigFlags_ViewportsEnable) != 0)
+ if (io.*.ConfigFlags & c.ImGuiConfigFlags_ViewportsEnable != 0)
unreachable;
// ImGui_ImplGlfw_InitPlatformInterface();
@@ -207,7 +207,7 @@ fn UpdateMousePosAndButtons() void {
var mouse_x: f64 = undefined;
var mouse_y: f64 = undefined;
c.glfwGetCursorPos(window, &mouse_x, &mouse_y);
- if (io.*.ConfigFlags & @enumToInt(c.ImGuiConfigFlags_ViewportsEnable) != 0) {
+ if (io.*.ConfigFlags & c.ImGuiConfigFlags_ViewportsEnable != 0) {
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
var window_x: c_int = undefined;
var window_y: c_int = undefined;
@@ -230,7 +230,7 @@ fn UpdateMousePosAndButtons() void {
fn UpdateMouseCursor() void {
const io = c.igGetIO();
- if (io.*.ConfigFlags & @enumToInt(c.ImGuiConfigFlags_NoMouseCursorChange) != 0 or c.glfwGetInputMode(g_Window, c.GLFW_CURSOR) == c.GLFW_CURSOR_DISABLED)
+ if (io.*.ConfigFlags & c.ImGuiConfigFlags_NoMouseCursorChange != 0 or c.glfwGetInputMode(g_Window, c.GLFW_CURSOR) == c.GLFW_CURSOR_DISABLED)
return;
const imgui_cursor = c.igGetMouseCursor();
@@ -238,13 +238,13 @@ fn UpdateMouseCursor() void {
var n: usize = 0;
while (n < @intCast(usize, platform_io.*.Viewports.Size)) : (n += 1) {
const window = @ptrCast(*c.GLFWwindow, platform_io.*.Viewports.Data[n].*.PlatformHandle);
- if (imgui_cursor == @enumToInt(c.ImGuiMouseCursor_None) or io.*.MouseDrawCursor) {
+ if (imgui_cursor == c.ImGuiMouseCursor_None or io.*.MouseDrawCursor) {
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
c.glfwSetInputMode(window, c.GLFW_CURSOR, c.GLFW_CURSOR_HIDDEN);
} else {
// Show OS mouse cursor
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
- c.glfwSetCursor(window, if (g_MouseCursors[@intCast(usize, imgui_cursor)]) |cursor| cursor else g_MouseCursors[@enumToInt(c.ImGuiMouseCursor_Arrow)]);
+ c.glfwSetCursor(window, if (g_MouseCursors[@intCast(usize, imgui_cursor)]) |cursor| cursor else g_MouseCursors[c.ImGuiMouseCursor_Arrow]);
c.glfwSetInputMode(window, c.GLFW_CURSOR, c.GLFW_CURSOR_NORMAL);
}
}
@@ -255,7 +255,7 @@ fn UpdateGamepads() void {
}
// GLFW Callbacks
-extern fn Callback_MouseButton(window: ?*c.GLFWwindow, button: c_int, action: c_int, mods: c_int) void {
+fn Callback_MouseButton(window: ?*c.GLFWwindow, button: c_int, action: c_int, mods: c_int) callconv(.C) void {
if (g_PrevUserCallbackMousebutton) |prev| {
prev(window, button, action, mods);
}
@@ -268,7 +268,7 @@ extern fn Callback_MouseButton(window: ?*c.GLFWwindow, button: c_int, action: c_
g_MouseJustPressed[button_u] = true;
}
-extern fn Callback_Scroll(window: ?*c.GLFWwindow, dx: f64, dy: f64) void {
+fn Callback_Scroll(window: ?*c.GLFWwindow, dx: f64, dy: f64) callconv(.C) void {
if (g_PrevUserCallbackScroll) |prev| {
prev(window, dx, dy);
}
@@ -278,7 +278,7 @@ extern fn Callback_Scroll(window: ?*c.GLFWwindow, dx: f64, dy: f64) void {
io.*.MouseWheel += @floatCast(f32, dy);
}
-extern fn Callback_Key(window: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, modifiers: c_int) void {
+fn Callback_Key(window: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, modifiers: c_int) callconv(.C) void {
if (g_PrevUserCallbackKey) |prev| {
prev(window, key, scancode, action, modifiers);
}
@@ -301,7 +301,7 @@ extern fn Callback_Key(window: ?*c.GLFWwindow, key: c_int, scancode: c_int, acti
io.*.KeySuper = io.*.KeysDown[c.GLFW_KEY_LEFT_SUPER] or io.*.KeysDown[c.GLFW_KEY_RIGHT_SUPER];
}
-extern fn Callback_Char(window: ?*c.GLFWwindow, char: c_uint) void {
+fn Callback_Char(window: ?*c.GLFWwindow, char: c_uint) callconv(.C) void {
if (g_PrevUserCallbackChar) |prev| {
prev(window, char);
}
diff --git a/src/main.zig b/src/main.zig
index 79dab91..ba1c92e 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -6,17 +6,21 @@ const debug_gl = @import("debug_gl.zig");
const glfw_impl = @import("glfw_impl.zig");
const gl3_impl = @import("gl3_impl.zig");
-extern fn errorCallback(err: c_int, description: [*c]const u8) void {
- panic("Error: {}\n", description);
+fn errorCallback(err: c_int, description: [*c]const u8) callconv(.C) void {
+ panic("Error: {}\n", .{ description });
}
var window: *c.GLFWwindow = undefined;
+fn handleStuff(path: [*c]const u8, x: i32, y: i32) callconv(.C) bool {
+ return true;
+}
+
pub fn main() !void {
_ = c.glfwSetErrorCallback(errorCallback);
if (c.glfwInit() == c.GL_FALSE) {
- panic("GLFW init failure\n");
+ panic("GLFW init failure\n", .{});
}
defer c.glfwTerminate();
@@ -31,8 +35,8 @@ pub fn main() !void {
const window_width = 640;
const window_height = 480;
- window = c.glfwCreateWindow(window_width, window_height, c"ImGUI Test", null, null) orelse {
- panic("unable to create window\n");
+ window = c.glfwCreateWindow(window_width, window_height, "ImGUI Test", null, null) orelse {
+ panic("unable to create window\n", .{});
};
defer c.glfwDestroyWindow(window);
@@ -43,9 +47,9 @@ pub fn main() !void {
defer c.igDestroyContext(context);
const io = c.igGetIO();
- io.*.ConfigFlags |= @enumToInt(c.ImGuiConfigFlags_NavEnableKeyboard);
- // io.*.ConfigFlags |= @enumToInt(c.ImGuiConfigFlags_DockingEnable);
- // io.*.ConfigFlags |= @enumToInt(c.ImGuiConfigFlags_ViewportsEnable);
+ io.*.ConfigFlags |= c.ImGuiConfigFlags_NavEnableKeyboard;
+ io.*.ConfigFlags |= c.ImGuiConfigFlags_DockingEnable;
+ // io.*.ConfigFlags |= c.ImGuiConfigFlags_ViewportsEnable;
const style = c.igGetStyle();
c.igStyleColorsDark(style);