Click to See Complete Forum and Search --> : DirectDraw
Pickleloaf
Feb 18th, 2001, 01:30 AM
Ok, I've finally managed to figure out the basics of DirectDraw.
1. Right now, I'm using windowed mode, with none of that flipping. How do I do the equivalent of a .cls?
2. I create a primary surface, and another surface to store a picture, but I have to use the Blt function, which is tedious. How do I find eg, Form.left in pixels? What must I do to enable BltFast?
3. How do I set a transparent color?
kedaman
Feb 18th, 2001, 01:37 PM
What do you mean by .cls?
form left property is in twips, to convert to pixels use either scaleX method or divide by screen.twipsperpixelx
there's no enable/disable BltFast.
applying a transparent color on a surface is done with setcolorkey:
Dim ColorKey As DDCOLORKEY
ColorKey.low = color
ColorKey.high = color
surface.SetColorKey DDCKEY_SRCBLT, ColorKey
drewski
Feb 19th, 2001, 12:04 AM
hey kedaman! how do you change the transparent color? all i know is 0 which is black. RGB() doesn't work.
kedaman
Feb 19th, 2001, 06:42 AM
RGB works but it converts color components to 24 bit color, so in case you use 16 or 8 it will return a different color, there's a color converter on fox page if i remember correct.
drewski
Feb 19th, 2001, 02:36 PM
cool! i'll check that out. thanks man
drewski
Feb 19th, 2001, 10:50 PM
hey kedaman i couldnt find it, do you think you could point me there?
kedaman
Feb 20th, 2001, 04:58 AM
I guess i could post them here, but i was sure i got the original version from fox page
Function RGB2DD(R As Byte, g As Byte, b As Byte, surface As DirectDrawSurface7) As Long
Dim temp As DDPIXELFORMAT
Dim Red!, Green!, Blue!, Alpha!
'Shift colors
Red = R / 255
Green = g / 255
Blue = b / 255
Alpha = 1
'Get the pixel format
surface.GetPixelFormat temp
'Return the scaled color
RGB2DD = (temp.lRGBAlphaBitMask * Alpha And temp.lRGBAlphaBitMask) + (temp.lRBitMask * Red And temp.lRBitMask) + (temp.lGBitMask * Green And temp.lGBitMask) + (temp.lBBitMask * Blue And temp.lBBitMask)
End Function
Function Color2DD(color&, surface As DirectDrawSurface7) As Long
Dim temp As DDPIXELFORMAT
Dim Red!, Green!, Blue!, Alpha!
'Shift colors
Red = color And 255
Green = color \ 256 And 255
Blue = color \ 65536 And 255
Alpha = 1
'Get the pixel format
surface.GetPixelFormat temp
'Return the scaled color
Color2DD = (temp.lRGBAlphaBitMask * Alpha And temp.lRGBAlphaBitMask) + (temp.lRBitMask * Red And temp.lRBitMask) + (temp.lGBitMask * Green And temp.lGBitMask) + (temp.lBBitMask * Blue And temp.lBBitMask)
End Function
drewski
Feb 20th, 2001, 07:52 PM
thanks man but i'm not sure i get what's happening in this code. also which one of these would i use for say 8 bit, 16 bit, and 24 bit color?
kedaman
Feb 21st, 2001, 01:47 AM
I guess the point is that you don't need to worry about the bits because of the bitmasks.
drewski
Feb 22nd, 2001, 12:08 AM
what? bit masks? now you're confusing me. are you saying that either of these will work? do i only use one of them or do i use both? i need more input here :(
kedaman
Feb 22nd, 2001, 02:31 AM
Bitmasks, i don't know much about them but the idea is that you can shrink the amount of colors by having in for instance the case with 16 bit, 6 or 5 bits for a color component instead of 8. So you have to ignore bit 7 and 8 and 6 too for red. Dunno why this algoritm do this scaling, but it i might be missing a point.
16 bit bitmask
0 1 2 3 4 5 6 7 8 9 A B C D E F
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 RED
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 GREEN
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 BLUE
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ALPHA
24 bit bitmask
0 1 2 3 4 5 6 7 8 9 A B C D E F1011121314151617
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 RED
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 GREEN
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 BLUE
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ALPHA
Anyways you should be able to use both of them, the first just takes in the color components instead of spliting them inside.
HarryW
Feb 22nd, 2001, 08:41 AM
That's assuming your graphics card's 16-bit colour is 5.6.5 style (R.G.B). Some (older) cards are 5.5.5 with one unused most significant bit, so it's actually 1.5.5.5 (X.R.G.B). That's also commonly called 15-bit colour.
drewski
Feb 22nd, 2001, 08:08 PM
hey, i just tested it out and it works! unfortunately it doesn't work for 8 bit color though. that's what i was planning on doing my game in. i could do it in 16 bit but i noticed that the fps are double if i have the screen res in 8 bit. do you know how to modify the rgb2dd() function so it will give me 8 bit color? thanks for the help.
kedaman
Feb 22nd, 2001, 08:38 PM
I have no idea who came up with the original algoritm, so i can't say but i guess if you don't have many bits per color component, then the surfaces get's ugly, unless you have palettes, and it might be hard to convert RGBcolors to nearest color in palette. Maybe you should look up the right color in the palette instead.
HarryW
Feb 22nd, 2001, 09:34 PM
I'm not entirely sure if this would work (or work efficiently), but you could use dds.GetDC() to get a DC for your surface, and then use the API call GetNearestColor (see here (http://www.allapi.net/api/GetNearestColor.php) for details) to find out which palette entry is closest... as I said I'm not convinced it will work but you could investigate it.
Otherwise, you could find your own colour-matching algorithm to find the palette entry in your palette with the nearest colour to one you want. The only way to do that that springs to mind would be a least-square method, or actually you probably wouldn't need to square it... I'll try to explain:
For each colour in the palette, you split it up into red, green and blue components (I'm assuming you're not using alpha), and subtract them from their corresponding red, greed and blue value in your desired colour. Take the absolute value (ie. make negative values positive) of the resulting three numbers and add them together. That sum is a measure of how far away the colour is from your desired colour. You do that for each colour in your palette, and pick out the one that's the closest match.
That's quite possibly a very bad way of finding the nearest colour, I expect there are better ways, but I don't know any.
drewski
Feb 22nd, 2001, 11:17 PM
for the color in GetNearestColor could i just us vb's RGB() function or should i use the one above? i think i might know how to do this. i could make a separate program, load the picture in a picbox, then use GetNearestColor to get the nearest color to the color i want out of the picture. then i could record that down as a constant and just use that from on out.
is this gonna work? i'm gonna try it. wish me luck.
drewski
Feb 24th, 2001, 07:20 PM
it didn't work :( i think i'll take a look out at planet source code.
drewski
Feb 25th, 2001, 11:47 PM
I couldn't find anything at planet source. :( If anyone can answer my question or knows of a site that might be of help my thanks would be immense!
This is really starting to bug me.
HarryW
Feb 26th, 2001, 12:27 AM
You could try the algorithm I was thinking of, see if that works. I'll try to write a function for it; you need to pass in an array of 256 palette entries, and the RGB colour you want that is closest. It returns the index in the array of the closest colour (I hope).
Function GetBestColourMatch(palette(256) As Long, ColourWanted As Long) As Long
Dim currIndex As Long
Dim currMatchValue as Long
Dim currBestIndex As Long
Dim currBestMatchValue As Long
currBestIndex = 1
currBestMatchValue = GetMatchValue(palette(1), ColourWanted)
For currIndex = 2 To 256
currMatchValue = GetMatchValue(palette(currIndex), ColourWanted)
If currMatch < currBestMatch
currBestMatchValue = currMatchValue
currBestIndex = currIndex
End If
Next currIndex
GetBestColourMatch = currBestIndex
End Function
Function GetMatchValue(TestColour As Long, ColourWanted As Long) As Long
Dim TestRed As Long
Dim TestGreen As Long
Dim TestBlue As Long
Dim WantedRed As Long
Dim WantedGreen As Long
Dim WantedBlue As Long
Dim RedDiff As Long
Dim GreenDiff As Long
Dim BlueDiff As Long
TestRed = TestColour And 255
TestGreen = TestColour \ 256 And 255
TestBlue = TestColour \ 65536 And 255
WantedRed = WantedColour And 255
WantedGreen = WantedColour \ 256 And 255
WantedBlue = WantedColour \ 65536 And 255
RedDiff = (TestRed - WantedRed)
GreenDiff = (TestGreen - WantedGreen)
BlueDiff = (TestBlue - WantedBlue)
GetMatchValue = RedDiff * RedDiff _
+ GreenDiff * GreenDiff _
+ BlueDiff * BlueDiff
End Function
I think that should work, more or less. It's just an idea, haven't tested it or anything.
drewski
Feb 26th, 2001, 04:17 PM
thanks i'll try that out, but what if i already know position of the color in the pallete? how could i get the RGB value for that?
kedaman
Feb 26th, 2001, 04:44 PM
I guess it's simple as follows:
surface.GetPalette DirectDrawPalette
DirectDrawPalette.GetEntries 0, 100, PALETTEENTRYarray
PALETTEENTRYarray(position).blue
PALETTEENTRYarray(position).red
PALETTEENTRYarray(position).green
No need to waste cpu for splitting up colorcomponents ;)
drewski
Feb 27th, 2001, 07:35 PM
cool! that takes the guess work out of it. but one more question:
PALETTEENTRYarray(position).blue
PALETTEENTRYarray(position).red
PALETTEENTRYarray(position).green
these values here would i use them in the RGB() function?
also
DirectDrawPalette.GetEntries 0, 100, PALETTEENTRYarray
the 0 here is the start, is this the starting position in the array? and the 100 is the count, is this the number of values in the array?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.