OpenGL textures upside down?
Hi,
I am trying to go through the GLSprite demo project and I understand most of it pretty well. The one thing I don't get is why the texture that is rendered is upside down. I turned off the glRotate() command to just look at the rendered polygon. It's upside down compared to the bitmap file in the project resources. Is there a way to reorder the vertices to get the texture to display the way it is in the PNG file? The polygon and texture vertices are defined as:
// Sets up an array of values to use as the sprite vertices.
const GLfloat spriteVertices[] = {
-0.5f, -0.5f,
0.5f, -0.5f,
-0.5f, 0.5f,
0.5f, 0.5f,
};
// Sets up an array of values for the texture coordinates.
const GLshort spriteTexcoords[] = {
0, 0,
1, 0,
0, 1,
1, 1,
};
I am trying to go through the GLSprite demo project and I understand most of it pretty well. The one thing I don't get is why the texture that is rendered is upside down. I turned off the glRotate() command to just look at the rendered polygon. It's upside down compared to the bitmap file in the project resources. Is there a way to reorder the vertices to get the texture to display the way it is in the PNG file? The polygon and texture vertices are defined as:
// Sets up an array of values to use as the sprite vertices.
const GLfloat spriteVertices[] = {
-0.5f, -0.5f,
0.5f, -0.5f,
-0.5f, 0.5f,
0.5f, 0.5f,
};
// Sets up an array of values for the texture coordinates.
const GLshort spriteTexcoords[] = {
0, 0,
1, 0,
0, 1,
1, 1,
};
The way OpenGL loads pixel data is upside-down to the way most of the rest of the computing world works (OpenGL considers the first row of pixels to be the bottom one, and they go up from there), which produces images that appear to be upside-down when loaded and applied as a texture. The two most common ways I've seen to fix this are to flip your texture image vertically when it's loaded, or to invert the Y axis of your texture coordinates. To do the latter, in your example, you'd simply change your texture coordinates to this:
const GLshort spriteTexcoords[] = {
0, 1,
1, 1,
0, 0,
1, 0,
};
const GLshort spriteTexcoords[] = {
0, 1,
1, 1,
0, 0,
1, 0,
};
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL ES Textures Start White | demonpants | 5 | 5,990 |
Sep 3, 2009 06:40 AM Last Post: Skorche |
|
| opengl es font textures? | cool mr croc | 0 | 2,100 |
Aug 17, 2009 04:52 AM Last Post: cool mr croc |
|
| OpenGL ES Loading Textures | soulstorm | 5 | 5,313 |
May 25, 2009 07:21 AM Last Post: soulstorm |
|
| blitting tiled textures using openGL | jaguard | 6 | 3,609 |
Jan 12, 2009 05:16 AM Last Post: jaguard |
|
| OpenGL textures | green_ghost | 5 | 3,445 |
Sep 7, 2008 11:28 PM Last Post: green_ghost |
|

