PDA

View Full Version : Alpha component in the PNG files



Pswin
01-05-2008, 10:17 AM
hi
how can i use alpha channel in the PNG files with glDrawPixels function ( i use DevIL)?

HenriH
01-06-2008, 11:28 AM
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.

Pswin
01-06-2008, 02:24 PM
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);

ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
ilEnable(IL_ORIGIN_SET);

ilBindImage (ImgId);
ilutGLLoadImage("C:/kge.png");

Width = ilGetInteger(IL_IMAGE_WIDTH);
Height = ilGetInteger(IL_IMAGE_HEIGHT);
ilConvertImage(IL_RGBA,IL_UNSIGNED_INT);
sourcedata = ilGetData();

ilDeleteImages(1, &ImgId);


glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glRasterPos2i(0,0);
glDrawPixels(Width ,Height,GL_RGBA,GL_UNSIGNED_INT, sourcedata);

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

-NiCo-
01-06-2008, 02:33 PM
Did you check if the alpha values in sourcedata are non-zero?

N.

jwatte
01-06-2008, 10:34 PM
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.