Original Post
I''m trying to load a texture from a PNG file. However, the texture I get is black, only a few lines of colorful pixels at the rim of the texture. I can''t figure what''s wrong with my code. Here it goes:
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush My Homepage (C++ SDL OpenGL Game Programming)
GLuint tex;
bool loadPngTex(string fname)
{
// ... PNG loading stuff
// which I know is correct ''cause I''ve displayed a PNG in 2D
// with the same code
png_byte **imageData = png_get_rows(pngStruct, pngInfo);
GLubyte* newImage = new GLubyte[imageHeight * imageWidth * bytesPerPixel];
// reverse row order so that the lower left corner is 0,0
for (int i = imageHeight-1; i >= 0; i--)
{
memcpy(&newImage[imageHeight - i - 1], imageData[i], imageWidth * bytesPerPixel);
}
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, bytesPerPixel, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, newImage);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
delete newImage;
png_destroy_read_struct(&pngStruct, &pngInfo, NULL);
return true;
}
What''s wrong with this?
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush My Homepage (C++ SDL OpenGL Game Programming)