Original Post
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.
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.
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.
FreeImage_Initialise();
FIBITMAP* image = FreeImage_Load(FIF_PNG, "sprite0.png", 0);
if (!image) {
cout<<"Unable to load file!"<<endl;
system("PAUSE");
return false;
}
// Convert to 32 bit
FIBITMAP* temp = image;
image = FreeImage_ConvertTo32Bits(temp);
FreeImage_Unload(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
bits[pix*4+2]=pixels[pix*4+0];
bits[pix*4+1]=pixels[pix*4+1];
bits[pix*4+0]=pixels[pix*4+2];
}
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);
}
fclose(pFile);
FreeImage_DeInitialise();
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.