Enable OpenGL with X11 Forwarding

If you’re using macOS with X11 forwarding, you may see a crash like this when trying to run an OpenGL program:

$ glxinfo
name of display: localhost:10.0
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  149 (GLX)
  Minor opcode of failed request:  24 (X_GLXCreateNewContext)
  Value in failed request:  0x0
  Serial number of failed request:  17
  Current serial number in output stream:  18

The cause?

Indirect GLX is not enabled by default.

You can enable it by opening a new terminal window, running the below command, and then restarting your computer.

defaults write org.xquartz.X11 enable_iglx -bool true

Source information: https://bugs.freedesktop.org/show_bug.cgi?id=99146

XQuartz for macOS: https://www.xquartz.org/