Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lephyrius

macrumors newbie
Original poster
Mar 13, 2009
7
0
Im trying to use PNG:s as textures but the problem is that it doesn't work. I where using a PNG loader from a standard OpenGL library I used before but it still doesn't work at all. (Here is the link: http://www.iwr.uni-heidelberg.de/groups/ngg/CG200708/Txt/png.c)
Here is the code:

GLubyte* png_tex = ReadPNGFromFile (filename);
printf("GL Error %i \n" , glGetError());
if (png_tex)
{

glGenTextures (1, &texid);
glBindTexture (GL_TEXTURE_2D, texid);
printf("GL Error %i \n" , glGetError());

//glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexImage2D (GL_TEXTURE_2D, 0, format,
width, height, 0, format,
GL_UNSIGNED_BYTE, png_tex);

//for (int i = 0; i < width*height; i++)
// printf("%i", png_tex);

free (png_tex);
}
printf("GL Error %i \n" , glGetError());

I used the loop:

for (int i = 0; i < width*height; i++)
printf("%i", png_tex);

For looking if the loaded texture contained some data and it did. The problem is that I only get blank textures. So I believe I did something wrong in OpenGL ES and yes I have enabled texturing with: glEnable(GL_TEXTURE_2D);

The printf("GL Error %i \n" , glGetError()); All printed out zero so it should be OK. Is there a problem using a greyscale image as GL_Luminance?
 
I also had trouble with PNG's; I had to make sure they where saved as "interlaced" in photoshop and that they where under 128x128 in size... an issue i still haven't got round and can't seem to get any help with :(.
 
I also had trouble with PNG's; I had to make sure they where saved as "interlaced" in photoshop and that they where under 128x128 in size... an issue i still haven't got round and can't seem to get any help with :(.

So you mean I need to have 128x128 in texture size and then saved as interaced. Sounds kind of stupid. I also tried it and it didn't work. :(
 
No you shouldn't have to do that; it's a problem I'm running into. I mentioned it in case the same thing might be happening to you, seems it's not tough.
 
Ok! I found the badness!
I forgot set texture parameter so it scales correctly:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.