Archived

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

leroy

Texture loading with SDL

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
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