Add native macOS support (Cocoa + GLFW backends)#22
Merged
Conversation
added 6 commits
May 12, 2026 18:51
- Update cmake_minimum_required to VERSION 3.1.0...3.13 to silence policy warning
- Remove duplicate ${GLEW_LIBRARIES} link in gvr (GLEW::GLEW target is sufficient)
- Guard black border cropping in saveContent behind CROP_BLACK_BORDERS define (off by default)
- Replace unsupported CMP0045 OLD policy with TARGET existence checks
- Use non-namespaced target names in PROJECT_STATIC_LIBRARIES
- Use OpenGL/glu.h instead of GL/glu.h on macOS
Adds basewindow_cocoa.mm implementing the BaseWindow interface using Cocoa/AppKit instead of X11. Enabled by the USE_COCOA cmake option (defaults to ON on macOS). Uses double-buffered pixel rendering via Core Graphics, dispatch-based file watching, and native NSEvent handling.
Add ALLOW_SMALL_ZOOM define to imagewindow.cc that bypasses the minimum zoom clamp, allowing the image to be displayed smaller than the window with black borders.
Replace GLUT windowing with GLFW for native macOS support. Uses macOS GLUT framework for font rendering only. Adds abstraction functions (GLSwapBuffers, GLGetModifiers, GLSetWindowSize, GLSetFullscreen) and backend-neutral constants to decouple glworld.cc from GLUT. Handles Retina display scaling for mouse coordinates and text rendering. Double-buffer fullscreen toggle via is_fullscreen state tracking.
macOS's Metal-backed OpenGL 2.1 compatibility layer ignores gl_PointSize written by vertex shaders (GL_PROGRAM_POINT_SIZE is non-functional). Use glPointSize() from the application side on macOS instead. Also always allocate a size VBO (filled with 1.0 when no scan data) to avoid relying on glVertexAttrib1f for disabled arrays.
The option must be defined before it's checked, otherwise a clean build (no cached variables) skips the GLFW search and falls back to the GLUT backend.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds native macOS support for sv and plyv without requiring X11/XQuartz.
The changes are in 6 commits on top of the current master (2.6.68), totaling
about 1800 lines of new code across 20 files. Here's a summary:
configure_link_libs.cmake
GLSetFullscreen) and backend-neutral constants to decouple glworld.cc from GLUT
Build from scratch on macOS:
brew install glfw glew libtiff jpeg-turbo libpng
mkdir build && cd build && cmake .. && make -j4
No XQuartz needed. The changes are designed to be modular — the Cocoa and GLFW backends
coexist with the existing X11/Win32 backends via cmake options. Linux and Windows builds
should be unaffected.