Jump to content
  • Advertisement

Archived

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

MaxwellMurder

SDL_LoadBMP and OPENGL

This topic is 5746 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
×

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!