View Full Version : Image data loading

02-14-2003, 04:57 AM

I was wondering what people do, when they need to load image data for textures. I sthere some common library that one can use, or do everybody write their own loaders?

02-14-2003, 06:02 AM
Check this out: http://openil.sourceforge.net

02-14-2003, 06:31 AM
Some used every thing from the BMP loader in the glaux to custom TGA loader routines, or a image loading library.

The easest is just plain RAW image data, very simple to load.
The TGA uncompressed format also is very easy to load also lot's of examples of loading TGA. TGA support alpha channel which comes in handy with making transparency maps.

nehe.gamedev.net has tutors on loading textures BMP to TGA

Originally posted by Anders:

I was wondering what people do, when they need to load image data for textures. I sthere some common library that one can use, or do everybody write their own loaders?

02-14-2003, 11:32 PM
If you're making a very simple app or game, where you know only need a few textures, the raw format is very easy to load and use. The main problem with the raw format, however, is that you must know the dimensions of the texture before you load it. With any other format(.bmp's, tga's, etc), you can pull the size of the image from the image format. Uncompressed bmps and tga's have very easy-to-understand file-formats.

You can find the specifications for most file formats at http://www.wotsit.org

Now, you can cheat a bit with raw files. You CAN store the size and format of the texture in the filename. http://www.opengl.org/discussion_boards/ubb/smile.gif


When you load the file, you can parse out the texture dimensions and pixelformat from the filename, and you're good to go. It all depends on the size of your project. If you're going to use 4-5 textures, stick with the raw format. If you want to use more, look into bmp's and tga's. There are libraries that let you load .jpgs, etc., but I haven't been too impressed with the loss of quality that jpgegs tend to display when used as textures.

If you do insist on using raw textures, Photoshop and Paintshop Pro have a .raw option. When you save the file, make sure it has a header size of 0 and is in interleaved format. From that point, this is all you need to do to load the file into a texture:

//this function returns 1 if it successfully loads a texture, 0 if it failed to load the file
int LoadTexture(void){
FILE *ifile;
// the size of a raw texture is equal to:
//it's height x it's width x the amount of bytes per pixel
//A 256x256 rgb texture is 256x256x3 bytes(196,608 bytes)
GLubyte texture[196608];
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);





gluBuild2DMipmaps(GL_TEXTURE_2D,3,256,256,GL_RGB, GL_UNSIGNED_BYTE, &texture[0]);
return 1;
return 0;

That should just about cover loading .raws as textures. http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by delsydsoft (edited 02-15-2003).]