Jump to content
  • Advertisement
Sign in to follow this  
KyosukeNo1

Render to textures but with a reverse order?

This topic is 4879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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~~~~~~

Share this post


Link to post
Share on other sites
Advertisement
If you want to reverse the order for texture data use this code

unsigned char *tmp=new unsigned char [x*y*l];
int i,j;
for (i=0;i<x*y*l;i++){
tmp=data[x*y*l-1-i];
}
for(i=0;i<x*y*l;i=i+x*l){
for (j=0;j<x*l;j++){
data[i+j] = tmp[i+(x*l-1)-j];
}

}
delete []tmp;



l is the number of channels like RGB 3 and data is an array for the texture data.

Share this post


Link to post
Share on other sites
Quote:
Original post by KyosukeNo1
...but (0,0) point for texture coordinate was on the upper-left...
The origin for texture coordinates is the lower-left (same with everything else in OpenGL), so your texture is being loaded upside-down. Depending on the file format you are using, it will be stored differently. Some formats have some data in it that says which way it is stored (TGA for example has this), so it's up to you to have all your data in the right order.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!