I am having real problems with trying to use pbuffers for offscreen rendering (requires GLX 1.3). My code compiles without bugs but I am getting the usual BadAlloc error messages. None of the available configurations that are returned by glXChooseFBConfig remove the BadAlloc error. Does anyone have working code for Linux? Or any ideas what I may be doing wrong?
My code:
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
// Compile with: ‘cc -I/usr/X11R6/include pbuffers.c -o pbuffers -L/usr/X11R6/lib -lGLU -lGL -lX11’
main() {
Display *dpy;
GLXFBConfig *fbconfig;
int screen;
GLXContext cx;
int fbconfigCount;
GLXPbuffer pbuffer;
int w=512, h=512;
int attribList[]={GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_MAX_PBUFFER_WIDTH, w,
GLX_MAX_PBUFFER_HEIGHT, h,
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_DRAWABLE_TYPE,GLX_PBUFFER_BIT,
GLX_DEPTH_SIZE, 24,
None};
FILE *file;
unsigned char *pixels;
// Create display
dpy = XOpenDisplay(0);
// Set screen
screen = DefaultScreen(dpy);
// Configure frame buffer
fbconfig = glXChooseFBConfig(dpy,
screen,
attribList,
&fbconfigCount);
if (fbconfig == NULL | | fbconfigCount <= 0) {
fprintf(stderr, "P-Buffers not supported.
");
exit(0);
}
// Create P-Buffer
pbuffer = glXCreatePbuffer(dpy,
fbconfig[0],
NULL);
if (pbuffer == None) {
fprintf(stderr, "Failed to create P-Buffer.
");
exit(0);
}
// Create graphics context
cx = glXCreateNewContext(dpy,
fbconfig[0],
GLX_RGBA_TYPE,
NULL,
GL_TRUE);
if (!cx) {
fprintf(stderr, "Failed to create graphics context.
");
exit(0);
}
// Activate graphics context
if (!glXMakeContextCurrent(dpy, pbuffer, pbuffer, cx)) {
fprintf(stderr, "Failed to activate graphics context.
");
exit(0);
}
// If all the preceding commands execute OK, then all the OpenGL instructions
// will be executed in the offscreen buffer