linux float pbuffer problem...

Started by
1 comment, last by playmesumch00ns 18 years, 11 months ago
I'm having trouble using floating-point pbuffers under linux. I'm trying to use the code from the NVSDK example in my own app, but something in my setup must be wrong as it's not working. I set it up like so:

// Try making a float pbuffer
	if ( !pbuf.create( 256, 256 ) )
		cerr << "Could not create pbuffer!" << endl;
	else
		cerr << "Created pbuffer successfully!" << endl;
	
	pbuf.activate();
	ResizeFunc()(256, 256);
    glClearColor(0.5, 0.6, 0.7, 1.0);
    pbuf.deactivate();
	
	// make a float texture rect to hold it
	glGenTextures(1, &fptexture);
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
	glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA_NV, 256, 256, 0, GL_RGBA, GL_FLOAT, NULL);
		
	// Fragment programs to write and read it
	const char readTexRect[] =
    "!!FP1.0\n"
    "TEX o[COLR], f[TEX0].xyxx, TEX0, RECT;\n"
    "END\n";

    glGenProgramsNV(1, &readTextureRECT);
    glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, readTextureRECT);
    glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, readTextureRECT, strlen(readTexRect), (const GLubyte *)readTexRect);

    const char readTex2D[] =
    "!!FP1.0\n"
    "TEX R0, f[TEX0].xyxx, TEX0, 2D;\n"
    "MUL o[COLR], f[COL0], R0;\n"
    "END\n";

    glGenProgramsNV(1, &readTexture2D);
    glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, readTexture2D);
    glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, readTexture2D, strlen(readTex2D), (const GLubyte *)readTex2D);

which all goes just fine. Then in my display loop I try to draw into the buffer, then copy it to the floating-point texture. I get an error back from GL when I try to bind the float texture after drawing. The error I get is #1282(invalid operation)

                pbuf.activate();
		
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
		glMatrixMode( GL_MODELVIEW );
		glLoadIdentity();
		
               // +++++++++++++++++++++++++++++++++++++++++++++++
               // DRAW SOME STUFF
		
		glEnable( GL_TEXTURE_2D );
		// copy contents of pbuffer to a texture
                
                // +++++++++++++++++++++++++++++++++++++++++++
                // +++++ FAILS ON THIS LINE ++++++++++++++++++++
   		glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
		
   		glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, width, height);
    	        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);

Binding the texture worked fine in the initialization process, so why not in the display loop. Can anyone see what I'm doing wrong?
Advertisement
Okay, it seems that drawing into the pbuffer is what's causing the error.

The glBindTexture and glCopyTexSubImage2D calls both work, and if I set the pbuffer's clear colour different from my window's clear colour, I can see that the pbuffer is being cleared, copied and then textured onto the quad correctly.

At first I though the problem might be in my drawing code - it just calls a display list, but even if I draw a glutSolidTeapot, it still errors. Does anyone have any idea what's going on?

Okay I've stripped it down to this. Doing anything at all inside glBegin()... glEnd() errors. An empty glBein() glEnd)( pair is fine, but it starts erroring as soon as I try to draw anything! It all works fine if I draw to the back buffer as normal. What am I doing wrong?

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 textureglBindTexture(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 pbufferglEnable(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();

This topic is closed to new replies.

Advertisement