• ### Announcements

#### Archived

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

## Recommended Posts

leroy    122
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);

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?