Advertisement Jump to content
Sign in to follow this  

Freeimage problem

This topic is 2841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Hmm yeah but i've drawn that image in photoshop. Its black circle. The background is tranparent

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!