PDA

View Full Version : Render to textures but with a reverse order?



David_dup1
06-08-2005, 03:13 AM
When I rendering my screen's result onto a texture, something happened:
The function "glCopyTexImage2D" gets pixels from bottom line to the top line (the (0,0) point was on the bottom left), but (0,0) point for texture coordinate was on the upper-left

So whenever I use the texture made from screen capture, I should use in an order like:
glTexCoord2f(0.0, 1.0); glVertex3f( -fRadii, 0, +fRadii );
glTexCoord2f(0.0, 0.0); glVertex3f( -fRadii, 0, -fRadii );
glTexCoord2f(1.0, 0.0); glVertex3f( +fRadii, 0, -fRadii );
glTexCoord2f(1.0, 1.0); glVertex3f( +fRadii, 0, +fRadii );
The upper-left point has texture coordinate (0,1), but lower-left gets (0,0).

It's quite uncomfortable and how could I do when I mix up the textures from file and from screen capture? Help~~~~~~

Moreover, I tried to get the data from texture and then reverse the order, but I get some strange result from the texture. Is this code right?
void* pData = new int[DEMO_WIN_WIDTH*DEMO_WIN_WIDTH*4];
glGetTexImage( GL_TEXTURE_2D, 3, GL_RGB, GL_UNSIGNED_INT, pData );
glGenTextures( 1, &this->m_nGLTextID_Ptn_2 );
glBindTexture( GL_TEXTURE_2D, this->m_nGLTextID_Ptn_2 );
glReadPixels( 0, 0, DEMO_WIN_WIDTH, DEMO_WIN_WIDTH, GL_RGB, GL_UNSIGNED_INT, pData );
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, TILE_WIDTH, TILE_WIDTH, GL_RGB, GL_UNSIGNED_INT, pData );

idr
06-09-2005, 07:45 AM
This is a beginner question.

OpenGL measures coordinates for everything (except point sprites (http://oss.sgi.com/projects/ogl-sample/registry/ARB/point_sprite.txt) ) with (0,0) in the lower-left.