PDA

View Full Version : about pbuffer , can you help me to find the problem?



Hichill
10-07-2004, 05:35 PM
my display function is as following ,but I can not any image shown on the screen, why?

hDC = wglGetCurrentDC();
hGLRC = wglGetCurrentContext();////获得当前DC和上下文
glGenTextures(1, &texture);
glEnable( GL_TEXTURE_RECTANGLE_NV );
glBindTexture(GL_TEXTURE_RECTANGLE_NV, texture );
glTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER,
GL_LINEAR );
glTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE );
init_pbuffer( &pbuffer, winWidth, winHeight);

// }
if (!wglMakeCurrent(pbuffer.hdc,pbuffer.hglrc)){
MessageBox(NULL,"Could not make p-buffer current!",
"ERROR",MB_OK|MB_ICONEXCLAMATION);
}
wglReleaseTexImageARB(pbuffer.hpbuffer, WGL_FRONT_LEFT_ARB); ///在下次render前一定要release一下.



glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* draw six faces of a cube */
glBegin(GL_QUADS);
glColor3f(1,1,0);
glNormal3f( 0.0F, 0.0F, 1.0F);
glVertex3f( 0.5F, 0.5F, 0.5F);
glVertex3f(-0.5F, 0.5F, 0.5F);
glVertex3f(-0.5F,-0.5F, 0.5F);
glVertex3f( 0.5F,-0.5F, 0.5F);
glNormal3f( 0.0F, 0.0F,-1.0F);
glVertex3f(-0.5F,-0.5F,-0.5F);
glVertex3f(-0.5F, 0.5F,-0.5F);
glVertex3f( 0.5F, 0.5F,-0.5F);
glVertex3f( 0.5F,-0.5F,-0.5F);
glNormal3f( 0.0F, 1.0F, 0.0F);
glVertex3f( 0.5F, 0.5F, 0.5F);
glVertex3f( 0.5F, 0.5F,-0.5F);
glVertex3f(-0.5F, 0.5F,-0.5F);
glVertex3f(-0.5F, 0.5F, 0.5F);
glNormal3f( 0.0F,-1.0F, 0.0F);
glVertex3f(-0.5F,-0.5F,-0.5F);
glVertex3f( 0.5F,-0.5F,-0.5F);
glVertex3f( 0.5F,-0.5F, 0.5F);
glVertex3f(-0.5F,-0.5F, 0.5F);
glNormal3f( 1.0F, 0.0F, 0.0F);
glVertex3f( 0.5F, 0.5F, 0.5F);
glVertex3f( 0.5F,-0.5F, 0.5F);
glVertex3f( 0.5F,-0.5F,-0.5F);
glVertex3f( 0.5F, 0.5F,-0.5F);
glNormal3f(-1.0F, 0.0F, 0.0F);
glVertex3f(-0.5F,-0.5F,-0.5F);
glVertex3f(-0.5F,-0.5F, 0.5F);
glVertex3f(-0.5F, 0.5F, 0.5F);
glVertex3f(-0.5F, 0.5F,-0.5F);
glEnd();

wglMakeCurrent( hDC, hGLRC);

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glMatrixMode (GL_PROJECTION); // Select The Projection Matrix
glPushMatrix(); // Store The Projection Matrix
glLoadIdentity(); //Reset The Projection Matrix
glOrtho(0, winWidth, 0, winHeight, -1, 1); // Set Up An Ortho Screen
glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix
glPushMatrix(); // Store The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glBindTexture(GL_TEXTURE_RECTANGLE_NV,texture );
if( !wglBindTexImageARB(pbuffer.hpbuffer, WGL_FRONT_LEFT_ARB) ){
MessageBox(NULL,"Could not bind p-buffer to render texture!",
"ERROR",MB_OK|MB_ICONEXCLAMATION);
// assert(0);
}

glBegin( GL_QUADS );
// glColor3f(1,1,0);
glTexCoord2d(0,0 );
// glVertex2d(viewportPosition.left, viewportPosition.top);
glVertex2f(0,0 );
//glMultiTexCoord2d(GL_TEXTURE2_ARB,0, Size[1]);
glTexCoord2d(0, winHeight-1);
// glVertex2d(viewportPosition.left, viewportPosition.bottom);
glVertex2f(0, winHeight-1);
glTexCoord2d(winWidth-1,winHeight-1);
//glMultiTexCoord2d(GL_TEXTURE2_ARB,Size[0],Size[1]);
// glVertex2d( viewportPosition.right, viewportPosition.bottom);
glVertex2f( winWidth-1, winHeight-1);
glTexCoord2d(winWidth-1, 0);

//glMultiTexCoord2d(GL_TEXTURE2_ARB,Size[0], 0);
//glVertex2d( viewportPosition.right, viewportPosition.top);
glVertex2f( winWidth-1,0);



glEnd();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();


wglReleaseTexImageARB(pbuffer.hpbuffer, WGL_FRONT_LEFT_ARB);

roffe
10-07-2004, 09:27 PM
Here are some useful steps you might take when debugging render to texture problems. Some might feel redundant, but they eliminate doubt later on(well at least for me).General tip: check for errors on every call!

1. Activate pbuffer context . Render to pbuffer.
2. read back pbuffer contents. Check that something got rendered. If not, check pbuffer setup code, rendering code. If you think your rendering code is faulty, do glClears with different clear colors. Read back and check if anything gets written to the pbuffer.If using double buffering, watch your glReadBuffer.

3. COPY pbuffer contents to texture target.
4. Switch to fb context. Bind texture(regular bind,not pbuffer bind).Download texture using glGetTexImage. Same results as in 2? If not, you might gave context resource sharing problems.

5. Now bind texture to pbuffer. Download texture. Check results.If fails, check pbuffer binding parameters.

6. Use bound texture to render into framebuffer.
If fails, check fb rendering code.