View Full Version : about auxDIBImageLoad() function

06-06-2004, 10:46 PM
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!

06-06-2004, 11:16 PM
or use a HBITMAP to gluBuild2DMipmaps

06-07-2004, 05:10 AM
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.

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

06-08-2004, 10:07 PM
In your snippet above you're telling gluBuild2DMipmaps that it will get
BM.bmWidth*BM.bmHeight*3 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.bmWidth*BM.bmHeight*3 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