我正在尝试获取 gl 上下文,绑定 PixelBuffer 在其中绘制东西。我可以验证 glClearColor 之类的调用是否有效,但是我无法生成任何 gl 列表。我没有想法,这是代码:
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = NULL;
static glXMakeContextCurrentARBProc glXMakeContextCurrentARB = NULL;
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc) glXGetProcAddressARB( (const GLubyte *) "glXMakeContextCurrent" );
const char *displayName = NULL;
Display* display = XOpenDisplay( displayName );
static int visualAttribs[] = { None };
int numberOfFramebufferConfigurations = 0;
GLXFBConfig* fbConfigs = glXChooseFBConfig( display, DefaultScreen(display), visualAttribs, &numberOfFramebufferConfigurations );
if (!fbConfigs)
{
fprintf(stderr, "The OpenGL on this system does not support glXCreateContextAttribsARB or glXMakeContextCurrent.");
return;
}
int context_attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
None
};
GLXContext openGLContext = glXCreateContextAttribsARB( display, fbConfigs[0], 0, True, context_attribs);
int pbufferAttribs[] = {
GLX_PBUFFER_WIDTH, cols,
GLX_PBUFFER_HEIGHT, rows,
None
};
GLXPbuffer pbuffer = glXCreatePbuffer( display, fbConfigs[0], pbufferAttribs );
// clean up:
XFree( fbConfigs );
XSync( display, False );
if (glXMakeContextCurrent( display, pbuffer, pbuffer, openGLContext ) )
{
if (openGLContext)
fprintf(stdout, "Got context \n");
GLuint list = glGenLists(1);
fprintf(stdout, "Got list %d\n", list); // This is always zero.
glNewList(list, GL_COMPILE);
glEndList();
glClearColor(0, 1, 0, 0);