Archived

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

krez

transparency and color keys

Recommended Posts

krez    443
I am trying to use DirectDraw7 to program a game (the details are unimportant), and I already have it set up to make black (0) transparent, for non-rectangular sprites. However, for some reason, DirectDraw... oh dammit I forget the word... I know this word dammit! OK, well anyway, DirectDraw smooths out the edges. For example, if I have a white circle, it makes some pixels around it grey-ish, so it looks nicer against a black background (for an extra 2 points, can someone remind me what this is called?). So, I want to use a range of colors for my transparent key, for example 0 to something that is just slightly lighter than black. All of the tutorial I found about transparent blitting tell you how to set up a transparent color key, but none explain how to use a range for it. In the DirectDraw SDK docs, it says I must use the DDCKEY_COLORSPACE flag, but doing this crashes my program. I think there is more stuff I have to set up somewhere, but I have no idea where. Can someone toss me a bone, and explain how to do this (in VB preferably, since that is what I am using). Thanks a lot --- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites
Load Runner    122
you have to fill out a DDCOLORKEY struct

typedef struct _DDCOLORKEY{
DWORD dwColorSpaceLowValue; //from
DWORD dwColorSpaceHighValue; //to
} DDCOLORKEY, FAR* LPDDCOLORKEY;

then use SetColorKey function

HRESULT SetColorKey(
DWORD dwFlags,
LPDDCOLORKEY lpDDColorKey
);



Share this post


Link to post
Share on other sites
Colin Jeanne    1114
No, no, Load Runner, that code should be what he needs since I''m sure he can modify it for VB. The DDCOLORKEY structure has a value for the lowest value to colorkey and the highest value to colorkey. Every value in between will be colorkeyed.

So, if you set the low value to 0 and the high value to slightly lighter than black your antialiased (is that the word you were looking for?) circle should blit fine.

Invader X
Invader''s Realm

Share this post


Link to post
Share on other sites
krez    443
quote:
Original post by Invader X
No, no, Load Runner, that code should be what he needs since I''m sure he can modify it for VB. The DDCOLORKEY structure has a value for the lowest value to colorkey and the highest value to colorkey. Every value in between will be colorkeyed.
So, if you set the low value to 0 and the high value to slightly lighter than black your antialiased (is that the word you were looking for?) circle should blit fine.

ah yes, antialiased... i think i must have killed that brain cell, because i KNOW i knew it at one time
anyways, i know how to set up a color key, but this makes my program crash. i have the feeling that i didn''t set something, or am missing a flag somewhere... it works if key.hi=key.low, but if they are a range it crashes. do i have to initialize DirectDraw differently somehow? or maybe the surface that uses this key?

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites