PDA

View Full Version : Loading bitmap into Gluint [256 * 256] array



delta_z
10-25-2000, 01:40 PM
I'm trying to load a bitmap into a 256 x 256 array. I have currently loaded the bitmap into the Visual c++ project as a binary. Do I use the HBITMAP class and some how get a pointer to the binary and iterate it into the array. This is very complicated to me and would like a good example.

Chad

Inquisitor
10-26-2000, 02:24 AM
Well, I don't have a compiler right here, but the following lines should give you a hint at least.
The function GetDIBits is used for retrieving the raw pixel data from a windows bitmap. All you need is a HDC and a HBITMAP handle



GLubyte pointer_to_your_array[256*256*3];
// 1. prepare BITMAPINFOHEADER for GetDIBits
BITMAPINFOHEADER info;
info.biSize=sizeof(BITMAPINFOHEADER);
info.biWidth=256;
info.biHeight=-256; // we usually want a top-down-bitmap
info.biPlanes=1;
info.biBitCount=24;
info.biCompression=BI_RGB;
info.biSizeImage=0;
info.biXPelsPerMeter=10000; // just some value
info.biYPelsPerMeter=10000; // just some value
info.biClrUsed=0;
info.biClrImportant=0;
// 2. let's do it
GetDIBits(hdc,
hbitmap,
0,
256,
(void*)pointer_to_your_array,
(BITMAPINFO*)&info,
DIB_RGB_COLORS);
// 3. Now your array should contain the raw bitmap data

The pointer you've got to supply must point to an array at least 256*256*3 bytes large (*3, cause in the example above you want retrieve RGB data, so 3 byte per pixel are necessary).
Hope it helped (and hope it works - can't test it).

delta_z
10-28-2000, 05:31 AM
thanks for the help I got it working!