Skip to content

Added GLFW OpenGL 2 backend - #115

Open
aidenfoxx wants to merge 2 commits into
zig-gamedev:mainfrom
aidenfoxx:glfw-opengl2-backend
Open

Added GLFW OpenGL 2 backend#115
aidenfoxx wants to merge 2 commits into
zig-gamedev:mainfrom
aidenfoxx:glfw-opengl2-backend

Conversation

@aidenfoxx

@aidenfoxx aidenfoxx commented Aug 24, 2026

Copy link
Copy Markdown

This is basically only needed to make zgui compatible with fixed function OpenGL in MacOS, which doesn't support compatibility profiles in OpenGL 3.

The backend is self-contained since it only uses GL 1.1 entry points; it links the system GL library directly rather than resolving symbols through zopengl, which officially only targets modern core profiles. As a result, the ImGui backend code is a direct copy from ImGui v1.92.1 (currently used by the zgui).

Notes:

  • Consumers who want fixed function GL can import the system header directly via translate-c (example below).
  • Consumers who also link zopengl on Windows should pass .export_linkage = .weak, to the dependency, otherwise GL 1.x symbols collide.

build.zig:

    const gl_c = b.addTranslateC(.{
        .root_source_file = b.path("src/gl.h"),
        .target = target,
        .optimize = optimize,
    });
    const gl_mod = gl_c.createModule();
    exe.root_module.addImport("gl", gl_mod);

src/gl.h

// Taken from `imgui_impl_opengl2.cpp` 
#if defined(_WIN32) && !defined(APIENTRY)
#define APIENTRY __stdcall
#endif
#if defined(_WIN32) && !defined(WINGDIAPI)
#define WINGDIAPI __declspec(dllimport)
#endif
#if defined(__APPLE__)
#define GL_SILENCE_DEPRECATION
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant