• Advertisement

Archived

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

SDL_LoadBMP and OPENGL

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

How do I convert an SDL_LoadBMP into a format that is compatible with opengl so I can texture my model of Optimus Prime dagnammit?? It''s hard kicking ass as a massive Robot when your stuck in wire frame!!!

Share this post


Link to post
Share on other sites
Advertisement
This is something I''ve done:

  
GLuint loadTexture(const char *path)
{
SDL_Surface *surface = SDL_LoadBMP(path);
if( !surface ) return 0;
if((surface->format->BytesPerPixel != 3) &&
(surface->format->BytesPerPixel != 4)) return 0;
GLuint texture = 0;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
int retVal = gluBuild2DMipmaps(GL_TEXTURE_2D,
surface->format->BytesPerPixel,
surface->w,
surface->h,
surface->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB,
GL_UNSIGNED_BYTE,
surface->pixels);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

return texture;
}

The bitmap should hzave 24bit color depth. But you could (easily) rewrite it to handle 8bit images.

Share this post


Link to post
Share on other sites

  • Advertisement