   Texture problem
  Hi, I want to put texture into a simple square surface using OpenGL.I load a texture using this method{GLuint texture;    unsigned char * data;    FILE * file;int width = 256;int height = 256;    file = fopen( filename, "rb" );    if ( file == NULL ) {cout<<"error"<<endl;}    data = (unsigned char *)malloc( width * height * 3 );    fread( data, width * height * 3, 1, file );    fclose( file );    glGenTextures( 1, &mTextureID );glBindTexture( GL_TEXTURE_2D, mTextureID );glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR );    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0,GL_RGB,   GL_UNSIGNED_BYTE, data);    glDeleteTextures( 1, &mTextureID ); }then when i want to draw a primitive showing this texture i used this call:glEnable(GL_TEXTURE_2D);glPushMatrix();glBegin(GL_QUADS);{glTexCoord2f(0.0,0.0);glVertex2f(-20.0f, -20.0f);glTexCoord2f(1.0, 0.0);glVertex2f(20.0, -20.0f);glTexCoord2f(1.0, 1.0);glVertex2f(20.0, 20.0);glTexCoord2f(0.0, 10.0);glVertex2f(-20.0f, 20.0);}glEnd();I am trying to load a .png image. the problem is that it does not show the exact texture, it shows some colored image.Please suggest some way in which i can use some method to add simple texture to my opengl primitives.All suggestions are welcome   
  The GL side is correct. But you can't just read a png file like that, a png fle contains compressed image data, which needs to be decompressed before you can pass it to glTexImage2D.   ;Quote:Original post by HuntsManThe GL side is correct. But you can't just read a png file like that, a png fle contains compressed image data, which needs to be decompressed before you can pass it to glTexImage2D.SO what are the format which i can use. And does the drawing part is correct?;Quote:SO what are the format which i can use.You can use .png, but you'll need to load the file, decompress/extract the image data, and then upload *that* data to OpenGL.As HuntsMan noted, formats like PNG and JPEG aren't just raw image data that you can upload directly to OpenGL - rather, they generally consist of metadata such as image dimensions and so on, and compressed image data.To get the image data from an image file (.png, .jpg, etc.), you can use an image loading library such as DevIl, FreeImage, or SDL_image.Quote:And does the drawing part is correct?Could be. The glPushMatrix() call doesn't do anything and the brackets are purely cosmetic, but assuming everything else has been set up correctly, it should work correctly. (That's assuming a lot though - in order for it to work, the texture has to be bound, the transforms need to be set up correctly, culling needs to be set appropriately, etc., etc.)Also, be sure to use [ source ] tags (no spaces) when posting code.   ;  For one even if you managed to decompress the .png file it still would work,since your are calling :glGenTextures( 1, &mTextureID ), then glDeleteTextures( 1, &mTextureID ) before even using the texture. The texture id would become invalid upon deletion. Also if you are using the fix function pipeline you would also have to enable texture mapping.   ;  I suggest you use DevIL for decompressing png or jpeg imageshttp://openil.sourceforge.net   