0
votes

Im trying to show some textures in my program, and I have this code thats used to load bitmaps into openGL textures:

void LoadGLTextures()
{
  // Bitmap handle and structure
  HBITMAP hBMP;
  BITMAP  BMP;

  // Generate list of textures from resources
  byte Texture[] = {IDB_FONT, IDB_SKIN, IDB_PIANO};
  glGenTextures(sizeof(Texture), &texture[0]);

   // Iterate through texture list and load bitmaps
  for (int loop=0; loop<sizeof(Texture); loop++)
  {
    hBMP = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(Texture[loop]),
                          IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
    if (hBMP)
    {
     GetObject(hBMP,sizeof(BMP), &BMP);
     glPixelStorei(GL_UNPACK_ALIGNMENT,4);
     glBindTexture(GL_TEXTURE_2D, texture[loop]);
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);

  // Generate Mipmapped Texture (3 Bytes, Width, Height And Data From The BMP)
     gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);
     DeleteObject(hBMP);
    }
  }

And while my background skin loads, and gets drawn correctly, the other (piano) texture doesn't get drawn. Im sure the drawing code is correct because when i swap which texture is used (from the piano to the background texture, in this case), the other texture gets drawn. So i think the bitmap isn't being loaded correctly. But im not sure why? Is there something glaringly obvious i have overlooked?

The bitmap is 128*256 and 24 bit colour.

If you need any of the other code please let me know.

edit - If anyone knows of any librarys that would do what I require, please let me know

1
Where else has this question been posted?Zoot
Codeguru.com forums - Asked pretty much the exact same question there.Medicide
Most people don't mind that too much. Just make sure you aren't posting multiple times within the StackExchange family of sites, such as gamedev.stackexchange.com or programmers.stackexchange.comZoot

1 Answers

0
votes

It might not be working right because it's deprecated.

From http://www.opengl.org/wiki/Common_Mistakes:

gluBuild2DMipmaps - Never use this. Use either GL_GENERATE_MIPMAP (requires GL 1.4) or the glGenerateMipmap function (requires GL 3.0).

Edit: Also, you probably need to call glEnable(GL_TEXTURE_2D) for EACH texture unit, i.e. inside the loop where you call glBindTexture.