OpenGL ES PNG texture loader?

Discussion in 'iOS Programming' started by Lephyrius, May 17, 2009.

  1. Lephyrius macrumors newbie

    Joined:
    Mar 13, 2009
    #1
    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?
     
  2. BananaDuffle macrumors member

    Joined:
    Mar 29, 2009
    #2
    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 :(.
     
  3. Lephyrius thread starter macrumors newbie

    Joined:
    Mar 13, 2009
    #3
    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. :(
     
  4. BananaDuffle macrumors member

    Joined:
    Mar 29, 2009
    #4
    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.
     
  5. Lephyrius thread starter macrumors newbie

    Joined:
    Mar 13, 2009
    #5
    Ok! I found the badness!
    I forgot set texture parameter so it scales correctly:
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     

Share This Page