Archived

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

hammerstein_02

DirectDraw Colorkeying...

Recommended Posts

Hi, I have several questions on colour keying, firstly is it wise to use different colours for your colour keys throughout? I have often just used black as my colour key, but know that sometimes I am gonna want to use it. Which brings me to my next question. I created an image, using 0,255,0 as the background colour, I then set my object in the program to use 0,255,0 as the lo and high colour keys.. didn''t work. Why is this? Does it depend on the pixel format? As I am writing a wrapper for directdraw, can I simply create functions within the class to convert accordingly? Colour keys are something that has confused me for a while, and I don''t want to continue on not knowing how to use them properly.. Thanks for your time Hammer.. PS - Please don''t correct the spellings, I just read it back and realised that I am spelling colour the proper way.. I know that in directdraw it is DDCOLORKEY .. thanks.. =*= If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore =*=

Share this post


Link to post
Share on other sites
Indeed if depends on the pixel format. You can have a look at the ddutil.cpp file in your SDK samples directory \samples\Multimedia\Common ...

They use a SetColorKey method in the class CDisplay .. It converts a RGB color intro a compatible GDI Color ... It should work.

__________________________



Bruno Wieckowski
Lead Programmer
Exood4 Studios

Share this post


Link to post
Share on other sites
You need to convert the RGB components of your color key to whatever bitdepth you are currently using in the program. The most common formats you will see are 15bpp(555), 16 bpp(565), 24 and 32 bpp. It''s important to detect which mode you are currently running in and use color conversion functions appropriately. For example, in windowed mode, you should detect the current bpp of the desktop, and in fullscreen mode, requesting a 16 bpp color depth will actually get you a 15 bpp depth on some cards. DDraw provides facilities to determine this, and you should be able to figure it out from the docs. There are some resources which explain it online, but it''s been so long since I saw them I have no idea where they are. However, this link should prove useful for the actual converisons. I adapted that code to a ddraw wrapper I wrote in C a couple years back and it worked quite well.

Also, it is common to use the same color key for all transparent images. A common color to use is (255, 0, 255), because it''s not commonly used in the actual visible portion of the image. However, IMO your engine/wrapper/lib should have facilities for using any color-key desired rather than hard-coding a specific value. That way, if you decide you *do* need to use that color in an image, you can use a different color for the background.

Share this post


Link to post
Share on other sites