Recently, I wrote an OpenGL off-screen rendering C++ code for Yan’s group at Dr. Brain’s lab, NUS. They already have a C# version, but it’s on-screen and wrote in C# KDEEB. They want it can be run on Linux server with more powerful GPU. So they ask me to help them implement this. There are many things need to be noticed. So I keep my experiences here.
At first, I naively think that I can use GLFW with glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE)
, it looks like off-screen (when I test on my PC), but what really happen is the program still need XServer. Once I use ssh to launch my program, I got error message:
Xlib: extension "GLX" missing on display ":0".
And I search this on the internet, finally I found that I should not use library which depends on xorg. The solution is to use EGL to create context instead of GLFW, and use OpenGL ES to render instead of OpenGL and GLEW.
The needed libraries:
sudo apt-get install libegl1-mesa-dev libgles2-mesa-dev
Compilation options:
-L/usr/lib/nvidia-396 -lOpenGL -lEGL
References:
Besides, OSMESA(off screen mesa) can also do off-screen rendering. But this doesn’t support modern OpenGL(like shader?), and GPU acceleration.
Reference: