Upside down textures

I’m loading in a bitmap to use as an opengl texture, but my textures appear
upside down? Here’s the code I am using:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureImage->w, textureImage->h, 0,
GL_BGR, GL_UNSIGNED_BYTE, textureImage->pixels);

Thanks,
/Line72–
10:13:34 up 5 days, 13:56, 2 users, load average: 1.06, 0.60, 0.25

http://openglforums.com/tutorials/tutorial7.htmlOn Tue, 2002-12-17 at 10:14, Mark D’voo wrote:

I’m loading in a bitmap to use as an opengl texture, but my textures appear
upside down? Here’s the code I am using:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureImage->w, textureImage->h, 0,
GL_BGR, GL_UNSIGNED_BYTE, textureImage->pixels);

I’m loading in a bitmap to use as an opengl texture, but my textures appear
upside down?

A humble man once approached the oracle, saying: “Oh seer, my textures
appear upside down. What to do?”

The oracle, not answering to the question, asked the man, “where is
up?”

“Up is to the positive on y-axis.”

“Are you sure?”

“That’s how my scene is oriented.”

“Where is ‘up’ as the texture sees it?”

“Where texture coordinate is larger.”

“Does that texture coordinate have any relation to the scene’s
y-axis?”

And then the man realized his folly, swapped his texture coordinates,
and his code compiled like the wind and ran gracefully like a
white-tailed deer.–
Petri Latvala

I’m creating an object in maya and texturing it in maya then reading in the
.obj file which has texture coordinates already, but my textures are still
upside down. How do I go about flipping the image instead of re-figuring all
my texture coordinates ?

/Line72On Tuesday 17 December 2002 10:40, Petri Latvala wrote:

I’m loading in a bitmap to use as an opengl texture, but my textures
appear upside down?

A humble man once approached the oracle, saying: “Oh seer, my textures
appear upside down. What to do?”

The oracle, not answering to the question, asked the man, “where is
up?”

“Up is to the positive on y-axis.”

“Are you sure?”

“That’s how my scene is oriented.”

“Where is ‘up’ as the texture sees it?”

“Where texture coordinate is larger.”

“Does that texture coordinate have any relation to the scene’s
y-axis?”

And then the man realized his folly, swapped his texture coordinates,
and his code compiled like the wind and ran gracefully like a
white-tailed deer.


19:38:35 up 5 days, 23:21, 2 users, load average: 0.02, 0.03, 0.00

If you are using SDL Surfaces to load in images, the
reason is that SDL and OpenGL have inverted coordinate
systems. SDL with its roots in 2D graphics, typically
define 0,0 as the top left corner of your screen
(because it is usually memory convenient to start an
image at 0). Values increase as you go downward.
OpenGL attempts to be system agnositic and defines its
coordinate system like what you would see in a Math or
Physics course, which means lower values are at the
bottom and increase upward.

So you can do one of two things: You can accept the
fact that your images will always be inverted and
adapt your coordinate systems to deal with it, or you
can manipulate the image data and invert it before you
feed it to OpenGL. (I prefer the latter solution
because it is easier to cut and paste outside OpenGL
code without thinking and deal with other OpenGL
people.)

I posted a small piece of code a few months ago to
invert an SDL Surface. Go to the mailing list archive
under September and look up the topic:
SDL/OpenGL and texture mapping

By the way, you might watch out for the GL_BGR
extension if you need to deal with portable code.
GL_BGR didn’t make it into OpenGL until version 1.2
and Microsoft abandoned it at version 1.1. It is often
up to the video card vendor to support anything in
1.2. You can check out Sam’s testgl.c that comes with
the SDL source in the test directory on how to convert
SDL surfaces to OpenGL textures with the correct color
properties. (It’s in the same topic thread as above.)

-Eric

I’m loading in a bitmap to use as an opengl texture,
but my textures
appear
upside down? Here’s the code I am using:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
textureImage->w,
textureImage->h, 0,> GL_BGR, GL_UNSIGNED_BYTE, textureImage->pixels);


Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

I’m creating an object in maya and texturing it in maya then reading
in the .obj file which has texture coordinates already, but my
textures are still upside down. How do I go about flipping the
image instead of re-figuring all my texture coordinates ?

Create a surface with equal width and height, create two SDL_Rects
with width equal to that of the surface and height of 1, set x to

  1. Now, with a for loop from 1 to the height, set the other rect’s y
    to i and the other’s to height - i and blit. Then you have a flipped
    version of the other.–
    Petri Latvala