I'm using lodePNG to load texture from a png file but the program crashes when I load the texture.
char* filename = "texture.png";
unsigned width, height;
std::vector<unsigned char>image;
GLuint texture[1];
//decode
unsigned error = lodepng::decode(image, width, height, filename);
if(error) std::cerr << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, &image[0]);
I used VS 2010 to compile and there are no errors, but the crash happens when I call glTexImage2D. My system is Windows 7, with support for OGL 3.3 on the graphics card.
I have another system, which is a Mac OSX 10.6, and I'm always porting the code, and there are no problems with it on the Mac at all. Is there a suggested fix I could make so it will load the texture correctly on windows?
Here is the site where I got the lodePNG files: http://lodev.org/lodepng/