Skip to content

Add native macOS support (Cocoa + GLFW backends)#22

Merged
heikohimu merged 6 commits into
roboception:masterfrom
dscharstein:macos-native-support
May 14, 2026
Merged

Add native macOS support (Cocoa + GLFW backends)#22
heikohimu merged 6 commits into
roboception:masterfrom
dscharstein:macos-native-support

Conversation

@dscharstein
Copy link
Copy Markdown

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:

  1. Build fixes for modern CMake and macOS
  • Update cmake_minimum_required to 3.1.0...3.13 to silence policy warnings
  • Replace unsupported CMP0045 OLD policy with target-existence checks in
    configure_link_libs.cmake
  • Fix PROJECT_STATIC_LIBRARIES to use non-namespaced target names
  • Use <OpenGL/glu.h> instead of <GL/glu.h> on macOS
  • Remove duplicate ${GLEW_LIBRARIES} linking (keep GLEW::GLEW target)
  1. Native Cocoa backend for sv (bgui/basewindow_cocoa.mm)
  • New BaseWindow implementation using Cocoa/AppKit (NSWindow, NSView, Core Graphics)
  • Double-buffered pixel rendering eliminates flicker during panning
  • File watching via dispatch_source (replaces inotify)
  • Controlled by USE_COCOA cmake option (defaults ON on macOS)
  • Retina display support for mouse coordinates
  1. Minor sv enhancement: allow zooming out below fit-to-window
  • Configurable via ALLOW_SMALL_ZOOM define in imagewindow.cc
  • Also made black border cropping on capture configurable (CROP_BLACK_BORDERS)
  1. GLFW backend for plyv (gvr/glmain_glfw.cc)
  • Replaces GLUT for windowing; uses macOS GLUT framework for font rendering only
  • Added abstraction functions (GLSwapBuffers, GLGetModifiers, GLSetWindowSize,
    GLSetFullscreen) and backend-neutral constants to decouple glworld.cc from GLUT
  • Retina display coordinate scaling for mouse input
  • Stroke font for info line, bitmap font for help overlay
  • Requires GLFW (brew install glfw)
  1. Workaround for broken gl_PointSize on macOS
  • macOS's Metal-backed GL 2.1 ignores gl_PointSize in vertex shaders
  • Uses glPointSize() from the application side on macOS instead
  • Guarded with #ifdef APPLE so Linux/Windows behavior is unchanged

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.

Daniel Scharstein 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.
@heikohimu heikohimu merged commit 2410211 into roboception:master May 14, 2026
1 check passed
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.

2 participants