Note: You must be registered in order to post a reply.
|
Vankwysha |
Posted - Apr 27 2005 : 02:49:39 AM hi, this is my first post and i'm not exactly sure if this has been answered before, but oh well.
i'm using the directx sdk with vb.net, using the directdraw techniques described in the vbgamer tutorial, and ive been trying to make a main menu for my game. i am trying to make the images on the menu have a transparent background, but i don't know how to use colorkeys for any color except black (which is the default). i've tried pretty much every number that would make sense for these commands:
ck.ColorSpaceLowValue ck.ColorSpaceHighValue
however, i can't make the magenta (rgb 255,0,255) background of the images appear transparent. any help would be much appreciated. |
Vankwysha |
Posted - May 04 2005 : 06:49:45 AM thanks, the RGB function works fine |
Eric Coleman |
Posted - Apr 27 2005 : 2:49:31 PM I'm not familiar with directx 9, but I am familiar with how direct draw works in directx 7.
You'll have to do some more searching in the SDK for the appropriate functions because I don't know them. However, this should help to put you on the right track.
Various video cards can store color information differently from each other, and it's also different between different color depths. In directx 7 you could find out a particular surface stores color information by calling some functions to fill a surface capabilities (caps for short) structure (udt) with the appropriate information. The caps structure provides you with bit masks for a particular color. A RGB bit mask of (63488, 2016, 31) corresponds to 5 bits for red, 6 for green, and 5 for blue. This is what it looks like if you convert the numbers to binary, you can see how the sections of 1's don't overlap. Each is a mask. To use the mask to extract colors you would use a binary "AND" operation.
The masks of Red, Green, Blue 1111100000000000 0000011111100000 0000000000011111
If you're given a color that looks like 1001101110011101, you could use R = C AND RedMask to extract the red bits. The color R would be 1001100000000000. However, to manipulate the color you would have to shift the color 6(green) + 5(blue) bits to the right to give you a number in the range 0 to 31. This is to make math a bit easier. It's much easier to add and subtract values from the color with this range. If you don't, simply adding "1" to red isn't so easy. You would need to go from 1001100000000000 + 0000100000000000 because the value 0000100000000000 is the first "one" value within the red section of the number.
Of course, you didn't ask about all this, I think a little background information never hurts anyone.
To get colors other than the "pure" colors, you have to do this sort of manipulation. The pure colors would be all combinations of the red, green, and blue masks. These include the colors black, white(red+blue+green), red, blue, green, magenta(red+blue), yellow(red+green), and cyan(green+blue).
To obtain the Magenta color key, you would use a binary "OR" operation to combine the blue and red bit masks. Simply Magenta = Red Or Blue. The Binary "OR" operation is like addition while "AND" is similar to subtraction. However, more appropriate terms would be more like "combination" and "extraction."
Here is directx 7 function for loading or creating a plain surface (i.e. not a texture) in directx 7. The color key stuff is at the very bottom. This may or may not be usefull for you. I'm not sure how directx 9 treats "surfaces", or if it even uses that terminology anymore. In Directx 7 direct draw and 3D are seperate, however, they can be used together. Directx 7 has two main types of surfaces, your plain direct draw surfaces and "texture" surfaces, which are using when drawing via 3D interfaces. In Directx 8, however, MS dropped direct draw, so everything was really a "texture." As for Direct Draw 9, I have no idea if plain surfaces still exist. If not, then you'll need to enumerate your texture formats to find a suitable choice.
Public Sub CreatePlainSurface(ByRef surface As DirectDrawSurface7, sFile As String, w As Long, h As Long) Dim bOK As Boolean Dim sLoadFile As String Dim i As Long Dim ddsd As DDSURFACEDESC2 Dim Init As Boolean Dim ddpf As DDPIXELFORMAT Dim cKey As DDCOLORKEY ddsd.lFlags = DDSD_CAPS If ((h <> 0) And (w <> 0)) Then ddsd.lFlags = ddsd.lFlags Or DDSD_HEIGHT Or DDSD_WIDTH ddsd.lHeight = h ddsd.lWidth = w End If If (g_device = "IID_IDirect3DHALDevice") Or (g_device = "IID_IDirect3DTnLHalDevice") Then ddsd.ddscaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_VIDEOMEMORY ddsd.ddscaps.lCaps2 = 0 Else ddsd.ddscaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY ddsd.ddscaps.lCaps2 = 0 End If If sFile = "" Then Set surface = root_dd7.CreateSurface(ddsd) Else Set surface = root_dd7.CreateSurfaceFromFile(sFile, ddsd) End If surface.GetPixelFormat ddpf cKey.high = ddpf.lRBitMask Or ddpf.lBBitMask cKey.low = cKey.high surface.SetColorKey DDCKEY_SRCBLT, cKey End Sub
|
Lachlan87 |
Posted - Apr 27 2005 : 10:44:25 AM Dim ck As ColorKey = New ColorKey ck.ColorSpaceHighValue = RGB(0, 255, 0) ck.ColorSpaceLowValue = RGB(0, 255, 0) sprite.SetColorKey(ColorKeyFlags.SourceDraw, ck)
This'll work until someone comes up with the "correct" method. I felt too lazy to look up the .NET version of the legacy RGB function. I made the color range be perfect green to perfect green, but you could make it a range of colors, like any color between light blue and dark blue, or whatever. If you need further explanation, just ask. |
Vankwysha |
Posted - Apr 27 2005 : 06:46:45 AM i'm using directx 9 and i havent read or heard any equivalent methods to what you are suggesting. i've tried using rgb, argb and hex values for the colorkey but none of them work. thanks for your time anyway.
The colorkey properties require a 32 bit integer, not a color enum or argb structure, so i'm not sure whether it should be the colour's position in the bitmap's colour table or what. |
masterbooda |
Posted - Apr 27 2005 : 06:27:36 AM Of course this depends on which version of directx you are using, you didn't state, so I am assuming its dx7..
If not, then I am sure there is an equivelant in higher versions...
DaBooda out... |
masterbooda |
Posted - Apr 27 2005 : 05:28:45 AM With directdraw, if memory serves me right. Your color key values have to match the bit depth of your .app, and they have to be in hex. Now with that being said, I'm not sure .net, makes this any diferent, but there is a built in command for making rgb colors. It does the bit shifting for you....its:
Directx7(object).CreateColorRGB(Red, Green, Blue).....the color ranges are 0 to 255...
and there is also
Directx7(object).CreateColorARGB(Alpha, Red, Green, Blue)....the color ranges are 0 to 255...
I hope this helps, use this command sparingly though, it tends to be a little slow..
DaBooda out.... |
|
|
VBGamer |
© |
|
|
|
|