About auxDIBImageLoad() function

auxDIBImageLoad(Filename);
This function need a char * parameter, but I have a HBITMAP.
How to conver the HBITMAP to AUX_RGBImageRec?
Can someone help me? Thank you!

or use a HBITMAP to gluBuild2DMipmaps

For gluBuild2DMipmaps, glTexImage2D and similar functions you need a pointer to the actual bitmap data.
Use GetDIBits API to get the pointer corresponding to your HBITMAP handle.

Thank you!
I found a article in codeguru sovle this problem.This is code:
BITMAP BM;
::GetObject (m_hBmp, sizeof (BM), &BM);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BM.bmWidth, BM.bmHeight,
GL_BGR_EXT, GL_UNSIGNED_BYTE,
BM.bmBits);
but another problem is happend.
If my BMP file’s bit-deep is less than 24, it will appear a error:Access voilation.

In your snippet above you’re telling gluBuild2DMipmaps that it will get
BM.bmWidthBM.bmHeight3 bytes of data.
When your bitmap has a depth of 24 bit (3*8) all is fine, but if it’s less, let’s say 16 bit, you will pass LESS allocated memory.
gluBuild2DMipmaps is still asuming you passed a 24 bit bitmap and runs in unallocated memory areas.
There you got your access violation.
Actually you could do it this way:

if(BM.bmBitsPixel!=24) {

  1. create array of size BM.bmWidthBM.bmHeight3 bytes
  2. convert the data BM.bmBits points to to RGB data and store resulting values in the array created above
  3. call gluBuild2DMipmaps with your array
  4. delete your array
    } else {
    just call gluBuild2DMipmaps the way you did before
    }

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.