Sign in to follow this  

Freeimage problem

Recommended Posts

I posted on the freeimage forum and 3 days still no reply. Googled like crazy can't find what I need so I'll might as well post my question here.Im trying to load transparent image(png) but I can't read the alpha.
GL_RGBA and nothing shows up on screen. If I use GL_RGB I get the image but there is a black background color where it should be transparent. Trying enabling blending and that didn't help either. So i though maybe freeimage isn't loading the alpha( nothing shown on screen when using RGBA) so I wrote short debug code which should write all the pixel information in a file.

FIBITMAP* image = FreeImage_Load(FIF_PNG, "sprite0.png", 0);
if (!image) {
cout<<"Unable to load file!"<<endl;
return false;

// Convert to 32 bit
FIBITMAP* temp = image;
image = FreeImage_ConvertTo32Bits(temp);

//Get image widht and height
int w = FreeImage_GetWidth(image);
int h = FreeImage_GetHeight(image);

BYTE *bits = (BYTE*)malloc( w * h * 4 );//allocate enough memory for the texture

BYTE *pixels = (BYTE*)FreeImage_GetBits(image);//read the image

for(int pix=0; pix < w * h; pix++){//swap some bits

FILE *pFile = fopen("debug.txt", "w");
char text[1000];
float r, g, b, a;
for(int pix = 0; pix < w * h; pix++){
r = bits[pix*4+0];g = bits[pix*4+1];b = bits[pix*4+2];a = bits[pix*4+3];
sprintf(text,"r %f g %f b %f a %f\n",r, g, b, a);
fputs(text, pFile);

I run the program and I get correct rgb values but the alpha is always 0 any idea why this happens.
If I use FreeImage_IsTranspararent(image) it return true. I don't know what to do anymore.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this