View Full Version : Alpha Channel of texture

12-30-2011, 07:21 AM
Hi there,

for 2 days i am trying to get a texture with aplha channel loaded, but i am not familiar enough with file formats to get it done.
i tryed .raw, .bmp, .png but could never get my load_img() function work right.

The best i could get was a whith spot where transparency should be... but i guess its because the .raw format does not support alpha channes ...


i know there are libs out there that offer easy load of texture, but i wanne understand it...

has anyone a example code that loads a .png file and uses alpha channes ... so i can use:

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, png_data);

thanx a lot

12-30-2011, 09:00 AM
I would just use DevIL unless you have something against using a open source library. DevIL handles a lot of formats including png. It uses libpng under the hood.

You can use libpng directly if you want but the API is ugly and requires a LOT of function calls. On the plus side, they have code examples so you can almost copy and paste. It is also a open source library.

12-30-2011, 12:24 PM
Thanx for the answer,

but has nobody here done a texture with alpha channes ?
or how does the 'data' need to look like that i pass to
glTexImage2D() as the last parameter when i use GL_RGBA ?

can someone give me a hint pls


Bruce Wheaton
12-30-2011, 12:31 PM
OpenGL doesn't have any functions to load textures from compressed formats. You could in theory open a raw RGBA type format - look for the NeHe tutorials, I think one does that.

For something like PNG, you are best to use a library - especially if you may need multiple formats.

But - was your initial code maybe OK? What should be showing through, if those are transparent objects, maybe it's white behind? Do you also have blending enabled properly?


Alfonse Reinheart
12-30-2011, 12:44 PM
OpenGL can read compressed formats. Just not typical image compression formats like PNG or JPEG. It uses S3TC/RGTC/BPTC.

12-30-2011, 01:44 PM
The simplest way to load a texture with alpha is to load .TGA files. HeNe give tutorials that show how to load such a file (which is basically a 12-byte header, followed by the raw data).
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data).