using glBitmap() and glDrawPixels()

Could anyone give me an example of loading a bitmap and displaying it using glBitmap() and/or glDrawPixels() in windows? I have been having some trouble getting it to work.

I am trying to display various different formats with glDrawPixels(), like BMP(1bit,gray4bit,gray8bit,indexColor8bit,rgb24).
Also trying to use glBitmap().

Can someone please help me!

AlesP

I found that glBitmap() only supports 8-bit bitmaps which are greyscale. To display 16 or 24 bit bitmaps we need to use glDrawPixels(). The only problem is that I still don’t know how to use it =(.

Well a bitmap in OpenGL is just that… a bit map. It isn’t even for 8-bit images, only 1-bit images. (Black & White, or more specifically your current color or no color) Each bit in the “bitmap” determines if that point in the image is on or off. If it’s “on” (in other words, that bit is 1) then the current color will be used for that location.

A BMP on the other hand is an image format that isn’t necessarily a “bitmap” in the same sense. Obviously bits are still important, but you use more of them per pixel to get a wider range of color.

So if you want to load a BMP to display, you have to do one of two things…

  1. Use glDrawPixels(). If you do this, you’ll want to make sure what format your data is in. BMP info is stored in BGR format which means that if you have a 1x2 BMP where the first pixel is blue, the second red your data would be like this

unsigned char data = {255/b/, 0 /g/, 0/r/, 0/b/, 0/g/, 255/r/};

// This will draw the “image” at the current
// raster position
glDrawPixels(1, 2, GL_BGR_EXT, GL_UNSIGNED_BYTE, data);

  1. Use a textured quad. This would probably be faster. You should really look in the Red Book for topics like these. It’s available somewhere online, though I don’t recall where exactly.

Just an additional note… OpenGL doesn’t provide file loading functions. You’ll have to learn the format yourself and code your own loader, or use someone elses (in the form of code, or a library.)