Hello,
I’m trying to use my TX2 to do some rendering, but with no display attached I can save some resources by not running X11. I’m trying to create an EGL context by following this example: https://devblogs.nvidia.com/egl-eye-opengl-visualization-without-x-server/
I’ve modified the code in the blog post to add some error checking, my code follows:
#include <EGL/egl.h>
#include <stdio.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
};
#define pbufferWidth 9
#define 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);
if (eglDpy == EGL_NO_DISPLAY) {
fprintf(stderr, "Failed to get EGL display\n");
return -1;
}
EGLint major, minor;
if (eglInitialize(eglDpy, &major, &minor) == EGL_FALSE) {
fprintf(stderr, "Failed to initialize EGL display: %x\n", eglGetError());
return -1;
}
// 2. Select an appropriate configuration
EGLint numConfigs;
EGLConfig eglCfg;
eglChooseConfig(eglDpy, configAttribs, &eglCfg, 1, &numConfigs);
if (numConfigs != 1) {
fprintf(stderr, "Failed to choose exactly 1 config, chose %d\n", numConfigs);
return -1;
}
// 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);
// from now on use your OpenGL context
// 6. Terminate EGL when finished
eglTerminate(eglDpy);
return 0;
}
When I run this code on my TX2 (without X11 running…), it fails at ‘eglInitialize’. Is there something else I need to do, or some other driver that must be loaded?
Thanks.