View Full Version : how are textures loaded?

09-16-2003, 05:25 PM

i understand this question is too basic, but...

last time i got this response:

"There are tho ways, a) use an existing library and b) write your own function, but you somehow have to get the image in the file into your memory, in the format you want it to have (for example RGB or RGBA).

I would recommend to either write a ppm/ascii-loader yourself (VERY easy) or use libjpg to load jpeg files (QUITE easy *g*)."

all right, so what is a ppm/ascii-loader and how do i write it. i also don't know how to load jp[eg files using libjpg.

could someone recommend some code samples for all this.


09-16-2003, 05:38 PM
PPM loaders are amazingly trivial to write; c.f. http://www.wotsit.org/download.asp?f=ppm for the file spec.

The basics are:
- read hte first line to work out what format it is
- read the width and height of the image
- read the pixel precision (ie. number that equals maxiumum intensity)
- read the pixel data, stored as *uncompressed* RGB pixels.


09-16-2003, 10:04 PM
Hi !

Just to clear things up a bit for you, ppm is a file format, just like bmp, jpeg and so on, it's pretty common in the unix world, and as said is very easy to handle, but there are not that many applications on windows that can read and write ppm files, even though I would gues that gimp on Windows might be able to help you.

The NeHe tutorials has a simple texture loader included if you want to take the easy way out...

Note: If your textures are not actual photos you should stay away from jpeg files (at least if you use compression) because the images will look like s**t.


[This message has been edited by mikael_aronsson (edited 09-17-2003).]

09-16-2003, 10:14 PM
Originally posted by just_started:
could someone recommend some code samples for all this.

Remember, google is your first line of defense. Always use it BEFORE posting... http://courses.cs.deu.edu.tr/cse566/newpage2.htm

more at www.ijg.org (http://www.ijg.org)