Results 1 to 22 of 22

Thread: DirectDraw

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    13
    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?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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:
    Code:
            Dim ColorKey As DDCOLORKEY
            ColorKey.low = color
            ColorKey.high = color
            surface.SetColorKey DDCKEY_SRCBLT, ColorKey
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    hey kedaman! how do you change the transparent color? all i know is 0 which is black. RGB() doesn't work.
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    cool! i'll check that out. thanks man
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  6. #6
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    hey kedaman i couldnt find it, do you think you could point me there?
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I guess i could post them here, but i was sure i got the original version from fox page
    Code:
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242

    cool

    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?
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I guess the point is that you don't need to worry about the bits because of the bitmasks.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    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
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Code:
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  13. #13
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    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.
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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 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.
    Harry.

    "From one thing, know ten thousand things."

  16. #16
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    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.
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  17. #17
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    it didn't work i think i'll take a look out at planet source code.
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  18. #18
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242

    #$%

    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.
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  19. #19
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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).

    Code:
    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.
    Last edited by HarryW; Feb 26th, 2001 at 01:33 AM.
    Harry.

    "From one thing, know ten thousand things."

  20. #20
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    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?
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  21. #21
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I guess it's simple as follows:
    Code:
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  22. #22
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    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?
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width