Listing 1: OpenGL initialization code for texture mapping polygon

void CGlrotateDlg::InitOpenGL()
{
  glDisable(GL_DEPTH_TEST);

  glClearColor (0.0, 0.0, 0.0, 0.0);

  // set up an orthographic projection ...
  GLfloat halfWidth  = m_fImageWidth/2.f,
          halfHeight = m_fImageHeight/2.f;
  
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity ();
  gluOrtho2D(-halfWidth+0.5f,  // left
             halfWidth-0.5,    // right
             -halfHeight+0.5f, // bottom
             halfHeight-0.5f); // top

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity ();

  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glPixelStorei(GL_PACK_ALIGNMENT, 1);

  // create an OpenGL texture map ...
  if (m_iTexName)
  {
    if (GL_TRUE == glIsTexture(m_iTexName))
    {
      glDeleteTextures(1, &m_iTexName);
    }
  }
  
  glGenTextures(1, &m_iTexName);
  glBindTexture(GL_TEXTURE_2D, m_iTexName);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

  glEnable(GL_TEXTURE_2D);

  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);  

  glTexImage2D(GL_TEXTURE_2D, 
               0, 
               GL_RGB, 
               m_image.width, 
               m_image.height, 
               0, 
               GL_RGB, 
               GL_UNSIGNED_BYTE, 
               m_image.data.begin());
  
  // create an OpenGL display list ...
  if (m_iDisplayListId)
  {
    if (GL_TRUE == glIsList(m_iDisplayListId))
    {
      glDeleteLists(m_iDisplayListId, 1);
    }
  }

  m_iDisplayListId = glGenLists(1);

  glNewList(m_iDisplayListId, GL_COMPILE);

    glBegin(GL_QUADS);

      glColor3f(1.0, 1.0, 1.0);

      // pixel to texel mapping ...
      GLfloat polyW = halfWidth-0.5f,
              polyH = halfHeight-0.5f;
      glTexCoord2f(0.0, 0.0); glVertex3f(-polyW,-polyH,0);
      glTexCoord2f(0.0, 1.0); glVertex3f(-polyW,polyH,0);
      glTexCoord2f(1.0, 1.0); glVertex3f(polyW,polyH,0);
      glTexCoord2f(1.0, 0.0); glVertex3f(polyW,-polyH,0);

    glEnd();
  
  glEndList();
}
— End of Listing —