How do I use this png loader?

Hello. I'm a newbie in c++ and opengl programming. Can someone explain how this png loader works? I just want to know how to use it. Thank you.

http://afsharious.wordpress.com/2011/06/30/loading-transparent-pngs-in-opengl-for-dummies/
Can someone explain how this png loader works? I just want to know how to use it.


The function is pretty self explanitory... just look at the function name and commented description:

1
2
3
4
5
6
7
8
9
10
11
12
 /** loadTexture
  *     loads a png file into an opengl texture object, using cstdio , libpng, and opengl.
  * 
  *     \param filename : the png file to be loaded
  *     \param width : width of png, to be updated as a side effect of this function
  *     \param height : height of png, to be updated as a side effect of this function
  * 
  *     \return GLuint : an opengl texture id.  Will be 0 if there is a major error,
  *                                     should be validated by the client of this function.
  * 
  */
 GLuint loadTexture(const string filename, int &width, int &height) 



Example usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int width = 0;
int height = 0;
GLuint texture = loadTexture( "name of your file.png", width, height );

if(!texture)
{
    // the load failed
}
else
{
    // the load succeeded.
    // 'texture' contains the OpenGL ID for the texture (ie, what you use with glBindTexture)
    // 'width' contains the width of the texture
    // 'height contains the height
}
Topic archived. No new replies allowed.