Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

leroy

Texture loading with SDL

This topic is 5751 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

Hello, I am trying to load textures using the texture loading routines (SDL_LoadBMP()) provided by SDL. This works ok, except that the red and blue channels are switched when I render a texture. How can this be? This is what it looks like so far:
  
GLuint tex;

glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

SDL_Surface* image = SDL_LoadBMP("test.bmp");
if (image->format->BytesPerPixel == 3) {
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 
        image->w, image->h, 0, GL_RGB, GL_UNSIGNED_BYTE,      
        image->pixels);
} else {
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 
        image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
        image->pixels);
}
  
Most of this code I''ve picked up from http://www.math.psu.edu/local_doc/SDL-1.1.2/opengl/examples.html and I think the above approach should work. Does anyone have any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Try GL_BGRA instead of GL_RGBA and GL_BGR instead of GL_RGB.

"To err is human, to really mess up requires a computer"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!