Archived

This topic is now archived and is closed to further replies.

JIMbond21

Alpha channel

Recommended Posts

Ok, Using the OpenGL tutorial for loading bitmaps the hard way, not using Glaux, on GameTutorials.com, I want to know if I load a 24 bit bitmap how do I exactally add the fourth byte for alpha channel, the tutorial uses CreateDIBSection to load the bitmap, but I want to load a 24 bit bitmap and add an alpha channel based on each pixels color when I load it, please don''t tell me to use tagra''s or something, there is a good reason for my specific question?

Share this post


Link to post
Share on other sites
An alpha channel is just a 4th byte added to each pixel, so in your array allocation (however this is accomplished) you need to allocate 4 bytes per pixel instead of 3. The first three bytes of a pixel block are the RGB data from your BMP file; the fourth byte is the alpha channel and (obviously) comes from another source.

I''m not too familiar with Windows programming, but I just took a quick look at the CreateDIBSection spec. at MSDN, and it looks like you will need to specify a bit depth of 32 in the biBitCount field of the BITMAPINFOHEADER bmiHeader member of the BITMAPINFO struct passed to CreateDIBSection(), in order to specify an RGBA bitmap array. You''ll also need to do the same in any other BITMAPINFO and BITMAPINFOHEADERs passed to any other functions (such as SetDIBits(), for instance) so that they know the format of the DIBSection.

As far as how you compute the alpha from the color of the pixel, that is up to you. You can specify that a certain RGB color combination (for instance, fuschia (255,0,255)) is equal to Alpha=0, to implement an index transparent color. Or you can use one of the color components and duplicate it for your alpha. It''s all entirely up to you.

Sorry if I can''t be more specific, as I am not all that familiar with Windows-specific calls.

Josh
vertexnormal AT linuxmail DOT org


Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.

Share this post


Link to post
Share on other sites