5
votes

I'm working on a game, and all of my graphics use magenta as transparent/magic color. They are all 32-bit and the magenta is just for conveniency. Anyway, I would appreciate if someone could advice me what library should I use to load my images (I need to load them in GL_RGBA format, both internal and texture specific).

5

5 Answers

6
votes

If only PNG support is necessary, use libpng. DevIL is supposed to be easy, but it's somewhat bloated (does a lot more than just load images) and internally actually calls OpenGL functions which can mess with your own OpenGL logic.

I personally prefer SDL_image, since I'm using SDL in my projects anyway. While not immediately obvious, SDL_BlitSurface() function can do the conversion from whatever IMG_Load() returns to the necessary pixel format.

5
votes

DevIL can load virtually every file format and can directly create OpenGL textures. It is the easiest way to go.

You should also use a file format which supports an alpha channel (PNG, TGA, ...). Using a "magic color" in 32-bit images is really out-dated!

1
votes

Apart from the other answers mentioning SDL and DevIL, there are two more options to consider:

  • Use libpng directly. This will probably have the smallest impact on the code size if that matters, since you get no bloat for other formats you're not using, no DLLs, etc.
  • Use operating-system texture loading. This can be a nice way to reduce dependencies if you prefer using OS features over external libraries. GDI+ in Windows XP and up has built-in texture loading for a few formats like PNG and JPEG, and I don't know for certain, but other OSs might have similar features. It's pretty simple to hook GDI+ up in to OpenGL and then the OS is taking care of your texture loading!
1
votes

There is a very minimalist one file example of loading a png into openGL here:

http://tfc.duke.free.fr/coding/src/png.c

0
votes

Another option is OpenCV.

It does a lot more than just texture loading, but odds are good you'll find use of its other features as well.