Jump to content
  • Advertisement

Archived

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

gameprogrammerwiz

color keying

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

ok, thnks to muzzfah (i think i spelled that right) i got my loop problem fixed...and i wrote a math function to display a map of 12x19 tiles. it works in a square type function, but with isometric tiles like so: <><><><><> <><><><><> <><><><><> <><><><><> <><><><><> this isnt exact, because of the spacing of the characters. but now i need to know how to color key. i found some sample code in a tutorial, but it didnt work. i dont think it was the full code though, because there was no string or integer to hold the RGB values. is there a way that i can point a color key to a specific surface and specify my own RGB value to blit out?

Share this post


Link to post
Share on other sites
Advertisement
To set a color key for each bitmap you can use DDSetColorKey. This function is in ddutil.cpp. just include ddutil.h

g_pDDSPlayer = DDLoadBitmap(m_pddraw, szPlayer, 0, 0);
DDSetColorKey(g_pDDSPlayer, RGB(0, 0, 0));

Or you can just use the code below using the SetColorKey function in DDraw.

DDCOLORKEY ddck;
ddck.dwColorSpaceLowValue = RGB(0, 0, 0);
ddck.dwColorSpaceHighValue = ddck.dwColorSpaceLowValue;
g_pDDSPlayer->SetColorKey(DDCKEY_SRCBLT, &ddck);


PigHeaded

Share this post


Link to post
Share on other sites
yeh, this stumped me for a long time. i use 32-bit surfaces and used the following code:

DDCOLORKEY colour_key;
colour_key.dwColorSpaceLowValue= _RGB32BIT(0,255,255,255);
colour_key.dwColorSpaceHighValue= ddck.dwColorSpaceLowValue;
g_pDDSPlayer->SetColorKey(DDCKEY_SRCBLT, &colour_key);

which technically should have worked, but it didnt.
alas, i found another way to do so. after the picture is loaded into the surface, make sure its locked, then do the above, but set

colour_key= {pointer to surface}[0]

which gets the first pixel and then sets the colour key to the first pixel of the pic (which is usual the one you want transparent.)

===================
i did:

DWORD *surface_mem = (DWORD *)ddsd.lpSurface;
// DWORD for 32 bit

then

colour_key.dwColorSpaceLowValue = surface_mem[0];
colour_key.dwColorSpaceHighValue = surface_mem[0];
etc...

Share this post


Link to post
Share on other sites
Also, if you''re using one of the ''primary'' colors (full red, full blue, full green, or any combination thereof including white) you can use the color mask(s) of your pixel format as a color as well.

They''re part of the DDPIXELFORMAT structure (I''m pretty sure that''s it), and there is one of those in the DDSURFACEDESC2 structure

David

Share this post


Link to post
Share on other sites
quote:
Original post by Verminaard

yeh, this stumped me for a long time. i use 32-bit surfaces and used the following code:

DDCOLORKEY colour_key;
colour_key.dwColorSpaceLowValue= _RGB32BIT(0,255,255,255);
colour_key.dwColorSpaceHighValue= ddck.dwColorSpaceLowValue;
g_pDDSPlayer->SetColorKey(DDCKEY_SRCBLT, &colour_key);

which technically should have worked, but it didnt.


Er, why do you use ddck.dwColorSpaceLowValue to set colour_key.dwColorSpaceLowValue? Surely that should have been colour_key.dwColorSpaceLowValue (to ensure it''s the same for -this- structure). I can''t see the whole code you were using, but for all I know, ddck might not even have been initialised yet.

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.

GameDev.net 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!