Jump to content
  • Advertisement

Archived

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

Mercury_Linx

OpenGL Source key in OpenGL ?

This topic is 6282 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

Dear All, Thanks in advance I have a bitmap and happend to have a colour RGB(0, 0, 0) as the source key for this bitmap, and how do I set the source key value in OpenGL so that it would not blit this part, and I don''t want to have a saperate image as the mask ? Mercury_Linx

Share this post


Link to post
Share on other sites
Advertisement
Run through at the image''s load time, and test each pixel to see if it is that color or not. If it is, make that pixel have a transparent (0,0,0) alpha value, otherwise make it have a opaque alpha value (255,255,255). Store it as GL_RGBA (32bit) so that the alpha channel is still there.

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/

Share this post


Link to post
Share on other sites
Thanks for the tip.

But what I did in Dirext Draw is setting the source key onto the offscreen surface e.g: lpDDSurf->SetColorKey( ... , ... )

I was wonder if there is anything similar in OpenGL, which I don''t need to go thru pixel by pixel in the bitmap file myself ... I try to avoid that



A programmer, is the soul creator for computers.

Share this post


Link to post
Share on other sites
>>But what I did in Dirext Draw is setting the source key onto the offscreen surface e.g: lpDDSurf->SetColorKey( ... , ... )
I was wonder if there is anything similar in OpenGL, which I don''t need to go thru pixel by pixel in the bitmap file myself ... I try to avoid that<<

no, u need an alpha channel its not all bad news though with an alpha channel u can do nice blending effects

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
Thanks guys ! I''m really appreciate it

Oh ... by the way, is there any significant or different between using a bit mask or inspect the colour bit one by one during image loading time ? I''m talking in concern of hits on execution time and memory management.



...
A programmer, is the soul creator for computers.

Share this post


Link to post
Share on other sites
as most texture loading is done during init time, having an alpha channel will be far quicker.

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Of course if you load a 32 bit (RGBA) image instead of a 24 bit image (RGB) the operation takes 25% more time.
But you load the texture one time at the beginning of your app or when you need it.
In hardware OpenGL implementation you get the same speed (32 bit parallelism).
In other words you pay for extra 25% memory use but not in speed.

One of the reasons for the fact that does not exist any operation like SetTransparentColor() is that in general the alpha byte is used for blend (8 bit transparency) so every texel needs its own alpha level. It''s not an OpenGL limit but another example of glSimplicity.

Share this post


Link to post
Share on other sites

What you need is load your 24 bit bitmap into a 32 bit image

LPBYTE pImage = new BYTE[width*height*4];

When you load the bitmap pixel per pixel simply skip one byte (your file is a 24 bit image).

Then process your image with a loop like this

DWORD transparent_color = RGB(tred, tgreen, tblue);
// for example transparent_color = 0 (black)

for(long pix=0; pix< width*height; pix++)
{
BYTE r = pImage[(pix<<2) + 0];
BYTE g = pImage[(pix<<2) + 1];
BYTE b = pImage[(pix<<2) + 2];
BYTE a; // not still defined

DWORD rgb = RGB(r, g, b);

if(rgb == transparent_color)
a = 0;
else
a = 255;

pImage[(pix<<2) + 3] = a;
}

Remember to define glAlphaFunc(GL_GREATER, 0) and
glEnable(GL_ALPHA_TEST); Of course you need also to SetUp your image as GL_RGBA texture!

It''s not difficult!

Share this post


Link to post
Share on other sites
Thanks alot for all the info

To Andrea:

Any reasons "pix << 2" ? Is it that you assume that r, g, b and a is all together 4 byte ? But why ? I'm a little puzzled here ...

By the way, do you have a complete sample which I can have a look and try out ?

Thanks again ...


...
A programmer, is the soul creator for computers.


Edited by - Mercury_Linx on May 2, 2001 8:28:06 PM

Share this post


Link to post
Share on other sites
Yes, I''ve assumed you are using 32 bit RGBA (it''s one of the most used format);

Every pixel is described by 4 components : red, green and blue (for 24 bit RGB) and an additional component (alpha for 32 bit RGBA). Every component is one byte lenght so you have 256 different levels for every component.

There are different method to store data images however the most typical is to store images by rows in RGBA order.
If you use 32 bit RGBA images you have 4 byte for every pixel
( infact in my example pix<<2 == pix*4 )

NOTE: Some video cards don''t support 32 bit texture however you can send a 32 bit texture to the card (OpenGL drivers should convert the image in the right format)(I use also a Vodoo3)

I''m sorry for the code but I''ve not a simple example to show you ( I''ve written my own cryptic C++ classes )...you can find some good example on NeHe site.

Share this post


Link to post
Share on other sites

  • 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!