I want to render with OpenGL without an X Server.
Code taken from here https://devblogs.nvidia.com/egl-eye-opengl-visualization-without-x-server/ and slightly modified:
#include <iostream>
#include <EGL/egl.h>
#include <GL/gl.h>
static const EGLint configAttribs[] = {
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_DEPTH_SIZE, 8,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE
};
// static const int pbufferWidth = 9;
// static const int pbufferHeight = 9;
// static const EGLint pbufferAttribs[] = {
// EGL_WIDTH, pbufferWidth,
// EGL_HEIGHT, pbufferHeight,
// EGL_NONE,
// };
int main(int argc, char *argv[])
{
// 1. Initialize EGL
EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EGLint major, minor;
eglInitialize(eglDpy, &major, &minor);
// 2. Select an appropriate configuration
EGLint numConfigs;
EGLConfig eglCfg;
eglChooseConfig(eglDpy, configAttribs, &eglCfg, 1, &numConfigs);
// 3. Create a surface
// EGLSurface eglSurf = eglCreatePbufferSurface(eglDpy, eglCfg, pbufferAttribs);
// 4. Bind the API
eglBindAPI(EGL_OPENGL_API);
// 5. Create a context and make it current
EGLContext eglCtx = eglCreateContext(eglDpy, eglCfg, EGL_NO_CONTEXT, NULL);
// eglMakeCurrent(eglDpy, eglSurf, eglSurf, eglCtx);
eglMakeCurrent(eglDpy, EGL_NO_SURFACE, EGL_NO_SURFACE, eglCtx);
int ma = -1;
int mi = -1;
eglQueryContext(eglDpy, eglCtx, EGL_CONTEXT_MAJOR_VERSION, &ma);
eglQueryContext(eglDpy, eglCtx, EGL_CONTEXT_MINOR_VERSION, &mi);
std::cout << ma << "." << mi << std::endl;
std::cout << "Error " << (glGetError() != GL_NO_ERROR) << std::endl;
ma = -1;
mi = -1;
glGetIntegerv(GL_MAJOR_VERSION, &ma);
glGetIntegerv(GL_MINOR_VERSION, &mi);
std::cout << ma << "." << mi << std::endl;
std::cout << "Error " << (glGetError() != GL_NO_ERROR) << std::endl;
int n = -1;
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
std::cout << "Extensions " << n << std::endl;
// 6. Terminate EGL when finished
eglTerminate(eglDpy);
return 0;
}
The above code leads to output
4.6
Error 0
-1.-1
Error 0
Extensions -1
Cleary the OpenGL context is not working as expected here!
Any help is appreciated.
My setup is
Linux gpusrv 4.15.0-47-generic #50~16.04.1-Ubuntu SMP Fri Mar 15 16:06:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Ubuntu 16.04.6 LTS \n \l
nvidia-smi outputs
Wed Apr 17 15:44:34 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.48 Driver Version: 410.48 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Tesla V100-SXM2... Off | 00000000:04:00.0 Off | 0 |
| N/A 45C P0 56W / 300W | 0MiB / 16130MiB | 0% E. Process |
+-------------------------------+----------------------+----------------------+
| 1 Tesla V100-SXM2... Off | 00000000:06:00.0 Off | 0 |
| N/A 39C P0 55W / 300W | 0MiB / 16130MiB | 0% E. Process |
+-------------------------------+----------------------+----------------------+
| 2 Tesla V100-SXM2... Off | 00000000:07:00.0 Off | 0 |
| N/A 37C P0 53W / 300W | 0MiB / 16130MiB | 0% E. Process |
+-------------------------------+----------------------+----------------------+
| 3 Tesla V100-SXM2... Off | 00000000:08:00.0 Off | 0 |
| N/A 40C P0 55W / 300W | 0MiB / 16130MiB | 0% E. Process |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
nvidia-bug-report.log.gz (1.91 MB)