Original Post
hello guys, i try to render the scene on a texture through glReadPixels to read the frame buffer to the texture. but it turns out that the texture is solid white. i just don't know why. please help. here is the code:
//the buffer used to store the frame buffer
unsigned char *bmp=new unsigned char[1024*768*3];
//set camera
this->mainCamera->updataCamera();
//render something here
glEnable(GL_TEXTURE_2D);
//read the frame buffer, this seems to be right, cause i printed the data that
//is read in to the buffer bmp
glReadPixels(0,0,1024,768,GL_RGB,GL_UNSIGNED_BYTE,bmp);
//generate the texture
glBindTexture( GL_TEXTURE_2D, render_texture );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP );
//read the date from buffer bmp to texture
glTexImage2D(GL_TEXTURE_2D,0,3, 1024,768, 0, GL_RGB, GL_UNSIGNED_BYTE, bmp);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glColor4ub(255,255,255,255);
//select the texture
glBindTexture(GL_TEXTURE_2D,this->render_texture);
//render the quad with the texture
glBegin(GL_QUADS);
glTexCoord2i(0,0);
glVertex3i(500,-500,500);
glTexCoord2i(1,0);
glVertex3i(-500,-500,500);
glTexCoord2i(1,1);
glVertex3i(-500,-500,-500);
glTexCoord2i(0,1);
glVertex3i(500,-500,-500);
glEnd();
//disable the texture
glBindTexture( GL_TEXTURE_2D, 0 );
glDisable(GL_TEXTURE_2D);
//delete the buffer
delete bmp;
the scene is a solid white quad without any texture.