View Full Version : Texture flipped on gluSphere
08-30-2001, 04:50 AM
I loaded an image of the earth from a JPeg file as a texture and applied it to a gluSphere. The texture is flipped horizontally (the west coast is now the east coast, vv). Viewing the image in IE shows it oriented properly. What gives here? Is this a quirk of gluSphere or am I screwing up something? Anyone know how to flip a texture using the texture matrix?
08-30-2001, 05:20 AM
It's "normal" because image data is generally stored from top to bottom in file formats when OpenGL work with picture from bottom to top.
The most simple thing to do for resolve this is simply to flip your picture with a paint soft (the minimalistic Microsoft Paint can make this with .bmp format for example) before present it to your OpenGL texture reader.
Or use a TGA loader that don't reorganize the order of lines from top to bottom (cf. that conserve the initial line order of the TGA file format) : this sort of picture loader is very easy to code with uncompressed .tga file.
On another side, make a function that flip uncompressed picture data in central memory can be a good thing too.
Or last solution, use effectively one texture matrix that flip the t value (cf. T=1.0-t) of the texture coordinates (but this work only and only if the w vertice coordinate is equal to 1)
1 0 0 0
0 -1 0 1
0 0 1 0
0 0 0 0
08-30-2001, 05:45 AM
Thank you very much!
08-31-2001, 07:32 AM
Code for flipping an RGB image in memory ...
void FlipImage(const char* source, char* target,unsigned width,unsigned height)
for (int j=0;j<height; j++)
for (int i=0;i<width;i++)
unsigned jWidthI = j*width+i;
target[ jWidthI*3] = source[ ((height-1-j)*width+i)*3];
target[ jWidthI*3+1] = source[ ((height-1-j)*width+i)*3+1];
target[ jWidthI*3+2] = source[ ((height-1-j)*width+i)*3+2];
[This message has been edited by pleopard (edited 08-31-2001).]
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.