title: How to load texture Opengl?
body: <p>I found a useful post at this site, where some code is used to load a BMP
  This code should load the header, read out infos, go further, read data, generate texture and bin it. But it doesnt work. What am I doing wrong ? </p>
  
  <p>Texture Declaration : </p>
  
  <pre><code>GLuint texture[1];
  </code></pre>
  
  <p>BMP Loading : </p>
  
  <pre><code>void LoadTexture(char *filename)
  {
      FILE * file = fopen(filename,"rb");
  
      unsigned char header[54];
      unsigned int dataPos;
      unsigned int imageSize;
      unsigned int width, height;
  
      fread(header,1,54,file);
  
      dataPos    = *(int*)&amp;(header[0x0A]);
      imageSize  = *(int*)&amp;(header[0x22]);
      width      = *(int*)&amp;(header[0x12]);
      height     = *(int*)&amp;(header[0x16]);
  
      if (imageSize==0) {
          imageSize=width*height*3; 
          }
      if (dataPos==0) {
          dataPos=54; 
      }
      unsigned char data[imageSize];
      fseek(file, SEEK_SET, 53);
      fread(data,1,imageSize,file);
  
      fclose(file);
  
      glActiveTexture(GL_TEXTURE1);
  
      glGenTextures(1, texture[0]);
  
      glBindTexture(GL_TEXTURE_2D, texture[0]);
  
      glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, data);
  
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  
      glGenerateMipmap(GL_TEXTURE_2D);
  
      glBindTexture(GL_TEXTURE_2D, texture[0]);
  }
  </code></pre>
  
  <p><strong>EDIT</strong> : I printed out some values read from the header. The header seems to be read properly.</p>
  
  <p>Drawing : </p>
  
  <pre><code>int DrawGLScene(GLvoid)                         
  {   
      glLoadIdentity();
          glEnable(GL_TEXTURE_2D);                        
      glTranslatef(0.0f,0.0f,-5.0f);
          glActiveTexture(GL_TEXTURE1);
      glBindTexture(GL_TEXTURE_2D, texture[0]);
  
      glBegin(GL_QUADS);
  
          glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
          glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
  
          glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
          glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
  
          glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
          glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
          glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
  
          glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
          glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
          glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
  
          glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
          glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
  
          glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
          glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
      glEnd();
      glFlush();
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      return 1;                                   
  }
  </code></pre>