Can't load .png image using opengl texture

    #include <stdio.h>
    #include <GL/gl.h>
    #include <GL/glut.h>
    #define KEY_ESCAPE 27
    void display();
    void keyboard(unsigned char,int,int);
    GLuint LoadTextureRAW( const char * filename, int wrap );
    int main(int argc, char **argv) {
        glutInit(&argc, argv);                                    
        glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH );
        glutCreateWindow("Opengl Test");                              
        return 0;
    void display() {
        GLuint texture=LoadTextureRAW("ball.png",1);
        glBegin( GL_QUADS );
        glTexCoord2d(0.0,0.0); glVertex2d(0.0,0.0);
        glTexCoord2d(1.0,0.0); glVertex2d(1.0,0.0);
        glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0);
        glTexCoord2d(0.0,1.0); glVertex2d(0.0,1.0);
    // load a 256x256 RGB .RAW file as a texture
    GLuint LoadTextureRAW( const char * filename, int wrap )
        GLuint texture;
        int width, height;
    //    BYTE * data;
        int *data;
        FILE * file;
        // open texture data
        file = fopen( filename, "rb" );
        if ( file == NULL ) return 0;
        // allocate buffer
        width = 256;
        height = 256;
        data = (int*)malloc( width * height * 3 );
        // read texture data
        fread( data, width * height * 3, 1, file );
        fclose( file );
        // allocate a texture name
        glGenTextures( 1, &texture );
        // select our current texture
        glBindTexture( GL_TEXTURE_2D, texture );
        // select modulate to mix texture with color for shading
        // when texture area is small, bilinear filter the closest mipmap
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                         GL_LINEAR_MIPMAP_NEAREST );
        // when texture area is large, bilinear filter the first mipmap
        // if wrap is true, the texture wraps over at the edges (repeat)
        //       ... false, the texture ends at the edges (clamp)
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                         wrap ? GL_REPEAT : GL_CLAMP );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                         wrap ? GL_REPEAT : GL_CLAMP );
        // build our texture mipmaps
        gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,
                           GL_RGB, GL_UNSIGNED_BYTE, data );
        // free buffer
        free( data );
        return texture;
    void keyboard(unsigned char key, int mousePositionX, int mousePositionY) { 
        switch ( key ) {
            case KEY_ESCAPE:
                exit ( 0 );   

I followed this,

What should i do?

Rather than just posting code and saying “What’s wrong with this?” - try and explain clearly what you are trying to achive, what steps you have taken (providing relevant code where appropriate) and then explain what you are observing.

Mearly asking "What should i do? " is not helping us help you - how do we know what’s wrong unless you tell us?

It’s not loading that .png file, some say i need libpng to make the png to raw file. I can’t understand how to do it.

Avoid PNG files? Use an art package and convert to something you can load.
I made a choice many years ago to not rely upon someone elses work (library functions ).

What is an art package? Why don’t you want to rely upon someone elses work? What do you do then?

An art package like PhotoShop or Paintshop Pro.

Why don’t you want to rely upon someone elses work?

Because quite often these pojects end up as abandonware - either not updated or not updated quickly enough. I did not want my projects to rely upon a certain feature set and then find out that that feature is no longer available. I’d rather write my own.

That code you wrote, is that available in internet?

No. It would not help you either as it’s in Delphi.

I would also recommend Gimp. Freely available on Internet, can convert to most file types, and can do fairly advanced image manipulations.

If it’s in Delphi, then how do you use that with opengl-C/C++ ?

I translate the headers from C into Delphi; a long and tedious task. Delphi, like other langauages, is able to pass parameters to functions calls in a variety of ways to make them compatible with other languages.

Png is a compressed format, is like try to zip a text file and then try to open it with notepad.
If you want to use any format around (jpeg, png, gif, etc…) you need an algorithm to decompress it or otherwise the only compressed format that you can use with hardware acceleration is DDS.
You can find a lot of library to load picture with relative documentation on the web. Google is the way.
By the way, why are you trying to load the texture EVERY FRAME?
And to finish, openGL is not a C library or and header, openGL is an interface. Interface that you can implement in any language, there is an openGL implementation for every language that I know.