Sign in to follow this  
vlad_tepes

Loading Jpegs

Recommended Posts


#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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this