color keying
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?
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
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
ack, that didnt work, pigheadded. im not sure that i was putting the code in the right place. would that matter at all? if you need the code to look at it i can email it to you.
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...
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...
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
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
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement