View Full Version : How do I load a bitmap without using AUX ?
03-19-2003, 11:39 AM
Ive been following NeHe and created my own basecode and im now going to make a bitmap loading function and need to know how to load butmaps cause it think his method uses the aux library!
03-19-2003, 11:56 AM
2 solutions : either you implement it yourself, or you use a library to handle this (a library that is more recent than AUX of course).
To implement it yourself : get the bmp format specification, and follow carefully the guidelines. You can find the spec from programming sites such as http://www.wotsit.org .
To use a library : well, quite simple. Find a good library (ie, a library that has the functionality you need, not necessarily a library that makes your coffee...). You can find tons of loaders for bmp : search with google, you will have choice. A good image library can be found at : http://www.imagelib.org . It handles reading/writing of many formats (bmp, tga, jpg, png and others). It has other functions such as scaling, color conversion etc. Maybe a bit heavy if your only goal is to load a bitmap for texturing.
I have had real problems using Nehe's bitmap loader so I found another tutorial where the loading was done by reading the bitmap header and the rest of the other info, and creating the texture from there.
I cant find the code now but if I remember (and you still need it) I will post it tommorow.
03-19-2003, 01:28 PM
If you dont mind that code might help http://www.opengl.org/discussion_boards/ubb/smile.gif, i didnt have problems with NeHe's but ive heard bad stuff about the aux library so i would prefer not to have to use it
I also changed the code to check if the file uses the colour my files use for key coloring, if so it adds the alpha channel and sets the alpha to 1 where the colour matches. Very useful for me!
03-19-2003, 02:38 PM
I recently had to learn how to load images from files. I am now using a library and dealing with TIFFs, but initially I figured out how to read and display bitmaps.
Here's the code I wrote:
// pointer to bitmap
PUCHAR bitmap ;
// Bitmap file headers
BITMAPFILEHEADER bmFile ;
BITMAPINFOHEADER bmInfo ;
// Bitmap file handle
CFile hFile ;
// Bitmap size
DWORD size ;
// Open it
BOOL bLeft = fileLeft.Open( "test.bmp",
CFile::modeRead | CFile::shareExclusive | CFile::typeBinary ) ;
if ( ! bLeft )
// could not open file - handle error
// Get bitmap file headers
hFile.Read( (void*)(&bmFile), sizeof(bmFile) ) ;
hFile.Read( (void*)(&bmInfo), sizeof(bmInfo) ) ;
// Get size of bitmap
size = bmInfo.biSizeImage ;
// Store bitmap dimensions
bmWidth = bmInfo.biWidth ;
bmHeight = bmInfo.biHeight ;
// Read in bitmap
bmLeft = new UCHAR[ size ] ;
fileLeft.Read( (void*)bitmap, (UINT)size ) ;
I found a lot of info online about the BMP format, and I should mention that I'm not 100% certain this will work for all bitmaps. My bitmaps are 24-bit in DIB format and I haven't had any problems.
If you decide to write your own loader, it's a start. Good luck.
ps. I should point out that I'm using MFC. I'm sorry. Trust me, it wasn't my idea. But the concept is the same.
[This message has been edited by kanet77 (edited 03-19-2003).]
Slight error on my part, my BITMAP loader does use AUX. Its my TGA loader I was thinking of.
Sorry about that. Lucky kanet77 was on the ball.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.