Jump to content
  • Advertisement
Sign in to follow this  
vlad_tepes

Loading Jpegs

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

Advertisement

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

void LoadTexture(Model &model , const char *tex)
{
SDL_Surface *texture = IMG_Load(tex);

if(texture)
{
/* create texture */
glGenTextures(1, &model.tex_id);

glBindTexture(GL_TEXTURE_2D, model.tex_id);

/* load in texture */
glTexImage2D( GL_TEXTURE_2D , 0 , 3 ,
texture->w , texture->h , 0 , GL_BGR,
GL_UNSIGNED_BYTE , texture->pixels);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

SDL_FreeSurface(texture);
}
else
{
// should throw
cerr << "error : loading texture " << tex << "\n";
}
}


will load any image format

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!