Advertisement Jump to content
Sign in to follow this  

OpenGL red and blue switching

This topic is 4902 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!