Advertisement Jump to content
Sign in to follow this  

OpenGL FreeImage + OpenGL [solved]

This topic is 4902 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'm rewriting my image/texture interface using FreeImage The library is clean and powerful (and very fast!)...but now I should use my images as textures for GL. [smile] The problem is : FreeImage uses a 32-bit boundaries for the scanlines.
Example :

   Suppose I've an RGB image with width = 386 pixel
   The first row starts at  data + 0
   The second at  data + 1160  
   but 386 * 3 = 1158 : the distance between two successive lines is 2 bytes  longer.
   This is because the pitch must but be a multiple of 32 bits (4 bytes) so
   the line is padded with 2 extra bytes to reach 1160.
   I'm sure DX users know the term pitch because it's used in the DX surfaces. 
I come to this solution FreeImage has a powerful function to convert an image to raw bits using the bpp, the pitch and also the RGB masks used to map the color (RGB,BGR,RGBA,RGB555,...)
FreeImage_ConvertToRawBits(BYTE *bits,       
                           FIBITMAP *dib, 
                           int pitch, 
                           unsigned bpp, 
                           unsigned red_mask, 
                           unsigned green_mask, 
                           unsigned blue_mask, 
                           BOOL topdown FI_DEFAULT(FALSE));

So I can create a temporary raw bits buffer, pass it via Bind()/TexImage() and then delete it. The question: Is there a better way to do this? In other words, how works exactly the parameters in glPixelStorei()? In particular there is a way to specify the 32 bits boundaries with GL_UNPACK_ROW_LENGTH and GL_UNPACK_ALIGNMENT ? I read the specification ( here ) but it's not very clear. I can use the first solution of course but if a more elegant solution exists I'd like to use it. Any ideas? Thanks! [Edited by - blizzard999 on August 21, 2005 5:39:44 PM]

Share this post

Link to post
Share on other sites
Obviously a texture is 'power of two' so every image format with a width >= 32 should be safe (because its width is multiple of 32).

In practice

format min width to have a NULL 'extra pitch'
ALPHA (1bpp) 32 pix
RGB (3bpp) 16 pix
RGBA (4bpp) 8 pix

So I could use the raw bits conversion only for thin images.

A general solution ? [smile]

Share this post

Link to post
Share on other sites
Solved: I've choosen the solution I proposed.
So I can specify the exact format of the texture (ie ALPHA from an RGB image or swap raw BGR to RGB...)
After Bind() I destroy the byte vector (in reality I let it alive as static vector for future use)

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!