Alpha component in the PNG files

how can i use alpha channel in the PNG files with glDrawPixels function ( i use DevIL)?

How do you want to use it? If you want to draw transparent images, you need to set up correct blending modes before drawing anything. Check out, glBlend functions. You must also load the image as RGBA image, so it contains the alpha channel.

have a png file with alpha chanel but i cant use the alpha chanel in opengl in other word all of the transparent pixels shown dark
this is my code, where is my problem?

ilGenImages (1, &ImgId);


ilBindImage (ImgId);

Width = ilGetInteger(IL_IMAGE_WIDTH);
Height = ilGetInteger(IL_IMAGE_HEIGHT);
sourcedata = ilGetData();

ilDeleteImages(1, &ImgId);

glDrawPixels(Width ,Height,GL_RGBA,GL_UNSIGNED_INT, sourcedata);

and,when i enable bleding any thing dont be shown,

Did you check if the alpha values in sourcedata are non-zero?


Your code doesn’t call glEnable(GL_BLEND) to turn on blending.

Also, it is a LOT faster to draw a quad with a texture on it, than it is to draw pixels using glDrawPixels(). I suggest letting IL keep the image around, with a texture ID, and using that.