- - -
I frequently use Bitmaps in my OpenGL programs. Simply because their file format is ludicrously simple (at least in 24bit mode). Well, I did just enough research that I could open all the other colour depths too and read the headers. So, with that knowledge I wrote this very simple bitmap loader in C++. The code is short and should be quite easy to read. The functions are definitely easy to use.
BMPClass bmp;
BMPLoad(fname,bmp);
//texture data now in bmp.bytes
Code distributed under the GPL. If you do something cool then I may or may not care about it. Getting my name in some credits would be cool too, but only for blagging rights.

NB. Currently the code only supports bitmaps whose widths work out as multiples of 4 bytes. This is pretty much guarranteed in an OpenGL program, where textures have to be 2^n anyway. If anyone wants to modify the code to handle any width then it should be pretty easy for to do.
Update:
  • It seems this doesn't work on mac, for endian reasons i can't fix, unless someone wants to buy me a mac
  • However, I have now tested it on Linux. And fixed bugs relating to GIMPs unexpectedly short headers
  • Fixed Windows bug introduced by fiddling on Linux. Possibly fixed random error message
  • Fixed monochrome bitmaps, they now load without crashing. Thanks to Charles Rabier
  • There is now no .exe compiled example because I am too lazy to reboot to Windows to create one

Download BMP Loader



Valid HTML 4.01! Valid CSS!

If you don't see the sidebar, goto the main page
- - -