Original Post
I was battling with my code for today, and I pin-pointed the error of my sdl program instantly closing from error with the generation of my textures...
// in my DrawingGame definition source file
static void uploadImage( std::string & filename, GLuint & id )
{
SDL_Surface * tempt = IMG_Load(filename.c_str());
if(!tempt)
{
id = 0;
}
SDL_Surface * nCopy = SDL_CreateRGBSurface(SDL_SWSURFACE,tempt->w,tempt->h,32,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
#else
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
#endif
);
SDL_BlitSurface(tempt,NULL,nCopy,NULL);
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
nCopy->w, nCopy->h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, nCopy->pixels);
SDL_FreeSurface(tempt);
SDL_FreeSurface(nCopy);
}
void gameDraw::Render_2D::getSpriteSheets(const std::vector<std::string> & imagefiles )
{
std::vector<GLuint>::iterator it;
unsigned int nSize = imagefiles.size();
textures.insert(it,nSize, 0);
unsigned int i = 0;
BOOST_FOREACH( std::string image, imagefiles )
{
uploadImage(image, textures);
++i;
}
}