red and blue switching

Started by
2 comments, last by blizzard999 18 years, 8 months ago
I'm using SDL/OpenGL (as a lot of people should know by now [smile]). The textures for my quads are getting there red and blue values switched when they load, though. Any ideas why? Thanks. I really have no idea where the problem might lay - I'm using IMG_Load (sdl_image.h) to load the images, and they are saved in bitmap format (made in MS Paint, no less). Thanks.
my siteGenius is 1% inspiration and 99% perspiration
Advertisement
Its the way the SDL loads the images, to get around it just specifiy GL_BGR/GL_BGR_EXT as the image format
In what function?

EDIT

NM - 2 seconds of google wins! Thanks, phantom!
my siteGenius is 1% inspiration and 99% perspiration
I suppose you are using a RGB texture, right?
OpenGL by default uses a 32 bit alignment and unpack from the MSB (most significant bit!)(in practice GL 'inverts' red and blue)

Simply tell OpenGL just before TexImage what you want; what you want should be

glPixelStorei(GL_UNPACK_ROW_LENGTH, width_of_your_image); // you know this
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // 1 byte alignment
glPixelStorei(GL_UNPACK_LSB_FIRST, 1); // 1==TRUE

I've not the code here but I will make the corrections if something I wrote is not correct. But it should work; you have a lot of parameters to play with.

For the same reason if you try to read back the buffer in an RGB array and get a crash (like me:) ) you know the reason now (in this case you must specify PACK attributes)(or use RGBA).

This topic is closed to new replies.

Advertisement