Jump to content
  • Advertisement
Sign in to follow this  
Solano

Freeimage problem

This topic is 2687 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.

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.

Share this post


Link to post
Share on other sites
Advertisement
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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!