I’m trying to incorporate pbuffers into my renderer. I’m using the CFPBuffer code from the NVSDK, which works in their example application.
However, in mine, doing anything more than clearing the pbuffer causes an error 1282 (invalid operation).
An empty glBeing/End air is fine, but doing anything like drawing vertices, or modifying the transform stack, causes the error. I can’t for the life of me figure out what I might be doing wrong. Since the nvidia example works, it’s got to be something in my initialization, but I don’t know where to start looking!
int width = pbuf.getWidth();
int height = pbuf.getHeight();
pbuf.activate();
CHECK_GL_ERROR();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glBegin( GL_TRIANGLES );
glVertex3f( 0, 0, 0 ); // <----------- THIS ERRORS!
CHECK_GL_ERROR();
glVertex3f( 1, 0, 0 );
CHECK_GL_ERROR();
glVertex3f( .5, 0, .5 );
glEnd();
// copy contents of pbuffer to a texture
glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
CHECK_GL_ERROR();
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, width, height);
CHECK_GL_ERROR();
pbuf.deactivate();
CHECK_GL_ERROR();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// draw a single quad with the texture containing a snapshot of the
// floating point pbuffer
glEnable(GL_FRAGMENT_PROGRAM_NV);
glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, readTextureRECT);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
CHECK_GL_ERROR();
glTranslatef(-0.5, -0.5,-0.9);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
glTexCoord2f(width, 0.0); glVertex2f(1.0, 0.0);
glTexCoord2f(width, height); glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, height); glVertex2f(0.0, 1.0);
glEnd();
glDisable(GL_FRAGMENT_PROGRAM_NV);
CHECK_GL_ERROR();
glutSwapBuffers();