Every time I try to run my program, it gives me a reading violation when it reaches glTexImage2D. This is my code:
<Mod Note: Next time use the [ code ][ /code ] tags>
C++:
unsigned int loadImage(string filename, bool alpha = true) {
// You should probably use CSurface::OnLoad ... ;)
//-- and make sure the Surface pointer is good!
unsigned int id;
SDL_Surface* Surface;
SDL_RWops *rwop;
rwop = SDL_RWFromFile(filename.c_str(), "rb");
Surface = IMG_LoadPNG_RW(rwop);
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
int Mode = GL_RGB;
if (Surface->format->BytesPerPixel == 4) {
Mode = GL_RGBA;
}
glTexImage2D(GL_TEXTURE_2D, 0, Mode, Surface->w, Surface->h, 0, Mode, GL_FLOAT, Surface->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return id;
}
<Mod Note: Next time use the [ code ][ /code ] tags>