upside down bitmaps?!

hey all. i loaded a texture using SDL_image’s IMG_Load() function (also with SDL_LoadBMP()) and then i took the resulting SDL_Surface and made it into a texture. it all works except the texture is displayed upside down. i imagine this has to do with the orientation of the SDL_Surface->pixels member vs. opengl’s. but im not sure how to handle this. any ideas?

Jeremy

Don’t forget that, in a screen or a bitmap, the Y axis points down (origin in the top-left corner), and in OpenGL the Y axis points up so you’ll have to invert the Y texture coordinates.

I have no experience with SDL, but this is “standard” for every image format.

If you mean the “upside down” (as compared to OpenGL) is standard for every file format, then I have to make you dissapointed.

There are file formats with the origin in the lower left corner, suitable for direct OpenGL use. TGA and BMP files both have a dynamic origin. I believe BMP’s are normally stored with the origin in the lower left corner, with the ability to store them with the origin in the upper left. TGA’s not only have the ability to place the origin in the upper or lower side, but also choose between left and right side.

SGI’s file formats (BW, RGB, RGBAand SGI, and maybe here are more in the familly) all have the origin in the lower left corner.

how do i invert the y then? can i do it as i load the texture? cause it’s kind of a pain to do it when drawing.

Jeremy

Bob:
I made a lot of image loading stuff, but what I meant was the way they are normally stored in memory for use (when you work with various formats you should stick to one orientation).

Jeremy:
You can use the texture matrix to do it for you!

how do i do this with the texture matrix? i imagine before i draw it’s a glPushMatrix(), glxMode(GL_TEXTURE_MATRIX), glLoadIdentity(), then what? after that a glMatrixMode(GL_PROJECTION), glPopMatrix(). how do i use the texture matrix? (what do i multiply it with to swap the y axis?) i’m not very familiar with matrices.

Jeremy

I handle this problem just without making the problem… ?

I mean I solve it just using glTexCoord
with the values stored in the data array/file/whatever wich keeps the model to render, and I keep the attitude in using tkDib (tk is for beginners I admit) loading bmp files in 8 bit format.

You are right Andrea!

To repeat!

Simply remap your images/textures to be the way up you require by changing the specification of glTexCoord() … hint … reverse top and bottom …

Else, you will be creating all sorts of unnecessary problems …

Rob