Hi, I use opengl with SDL. this function works in my other programs. I have the function load a file in the same directory as the other files and it works.
Now my problem is that I use this in another program, and for some reason, it returns some absurdly large number. I coped over working files to see if it was the actual image files, and no it still doesn't work. I watch the value of id in this code. In my older program, it holds the value 1 before it returns. In my new program, it returns something like 3465094356 something stupid like that.
// Load a Texture and return the ID
unsigned int GRAPHICS::LoadTexture(const char *filename)
{
SDL_Surface* img = IMG_Load(filename);
if (img == NULL)
{
OutputDebugString("\"");
OutputDebugString(filename);
OutputDebugString("\" failed to load.\n");
return -1;
}
SDL_PixelFormat form = {NULL, 32, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 0, 255};
SDL_Surface *img2 = SDL_ConvertSurface(img, &form, SDL_SWSURFACE);
if (img2 == NULL)
{
OutputDebugString("\"");
OutputDebugString(filename);
OutputDebugString("\" failed to load. img2 == -1\n");
return -1;
}
unsigned int id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->w, img->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img2->pixels);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
SDL_FreeSurface(img);
SDL_FreeSurface(img2);
return id;
}
I don't understand at all why it would behave differently in each program.
Help is appreciated