OpenGL textures upside down?

Nibbie
Posts: 1
Joined: 2009.03
Post: #1
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,
};
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
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,
};
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Textures Start White demonpants 5 7,085 Sep 3, 2009 06:40 AM
Last Post: Skorche
  opengl es font textures? cool mr croc 0 2,418 Aug 17, 2009 04:52 AM
Last Post: cool mr croc
  OpenGL ES Loading Textures soulstorm 5 6,922 May 25, 2009 07:21 AM
Last Post: soulstorm
  blitting tiled textures using openGL jaguard 6 4,432 Jan 12, 2009 05:16 AM
Last Post: jaguard
  OpenGL textures green_ghost 5 3,912 Sep 7, 2008 11:28 PM
Last Post: green_ghost