views:

118

answers:

4

Hello, 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).

+4  A: 

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!

Danvil
peachykeen
+4  A: 

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.

atis
DevIL can be used to only load images (no OpenGL calls then) or to load images directly into OpenGL textures (which necessarily calls OpenGL functions).
Danvil
+1  A: 

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!
AshleysBrain
Any code sample for GDI+ loading?
Marcus Lindblom
AshleysBrain
Why bother about how to load images, when there are libraries around that do it for you.
Danvil
A: 

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

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

Nick