Results 1 to 19 of 19

Thread: DirectX Help [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    DirectX Help [Resolved]

    I am trying to learn DirectX7 - DirectDraw, and i believe i have the basics down after looking around at tutorials and everything, one thing i cannot figure out, is how to draw multiple Sprites using the Source Code i uploaded. I have been messing around with this source code to learn Directdraw...I can honestly say i am a BitBlt master, so i should understand any help easily.

    Can someone Please explain to me how to draw more than 1 sprite in the code uploaded.
    Attached Files Attached Files
    Last edited by psycopatchet69; Nov 30th, 2004 at 11:20 PM.

  2. #2

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256
    If someone doesnt want to look through the code and all that, at least help me with a link to an example of what i am looking for, heavily commented code is always helpful

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349
    I'll give it a whirl, just give me a minute...

  4. #4

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256
    Thanks man

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349
    Right now I'm adding this Type in so you can use more ships. I may not be done with it yet but it'll give you a general idea.

    VB Code:
    1. Public Type Sprite
    2.    
    3.     Width As Long
    4.     Height As Long
    5.     Zoom As Single
    6.     Surface() As DirectDrawSurface7
    7.     Facing As Long
    8.  
    9.  
    10. End Type
    Last edited by Jacob Roman; Nov 29th, 2004 at 11:40 PM.

  6. #6

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256
    If any of the extra code (zooming, and the background color stuff) is in your way, just delete it, i dont really need it, i was just using that file as a tutorial sort of thing....

  7. #7

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256
    Oh, and to tell you the truth, i dont exactly understand why your making a type, unless your planning on something a little further then what i had in mind, all i was looking for was just to be able to BLT two or more sprites onto the backbuffer at once....

    Code:
        BackBuffer.Blt DestRect, Ship(Facing), SrcRect, DDBLT_KEYSRC Or DDBLT_WAIT
    looking at that line, in the DisplaySprite Sub, In BItBlt I would copy the line and change the variables to draw another sprite, But that doesnt seem to work for me in this example, and if you could, please explain that....

  8. #8
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349
    That's the idea. Believe me. Just watch as soon as I get done.
    Last edited by Jacob Roman; Nov 29th, 2004 at 11:53 PM.

  9. #9
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349
    Got it. Hope this helps. Man that was an easy one:
    Attached Files Attached Files

  10. #10
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Make sure your using BltFast
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  11. #11
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349
    That's not what he was looking for but yeah, he can do that too.

    Your NEW attatchment is two posts above in case you missed it psycopatchet69.

  12. #12

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256
    Yes, That helps, thank you very much

  13. #13
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349
    Now you know why the Sprite Type was needed.

  14. #14
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Yah I just felt like pointing out that when it comes to game sprites you should use BltFast.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  15. #15

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256
    I do have yet another question, Transparency. As i said earlier, this was just learning tutorial thingy, and well, i learned from it. But what i didnt learnfrom it, was transparency. Is there an easy way to implement transparency?

  16. #16
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349
    If you are refering to transparency as alphablending, I believe it's unfortunately only possible using Direct3D and using TLVertex for 2D. Probably beyond your skills since you just started learning DirectX. But if you want source code anyways on it let me know.

    If you are refering to transparency as removing the background color from the sprite so only the spite is blitted, look in the LoadSprite:

    VB Code:
    1. Public Sub LoadSprite(ByRef Sprite As DirectDrawSurface7, File As String, bWidth As Integer, bHeight As Integer, [b]ColourKey As Integer[/b])
    2.  
    3. [b]Dim CKey As DDCOLORKEY[/b]
    4. Dim ddsdNewSprite As DDSURFACEDESC2
    5.    
    6.     'This routine loads sprites in the FObject file and sets their colour keys
    7.     ddsdNewSprite.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT           'Set the surface description to include the Capabilities, Width and Height
    8.     ddsdNewSprite.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN                    'Set the surface's capabilities to be an offscreen surface
    9.     ddsdNewSprite.lWidth = bWidth                                           'Set the width of the surface
    10.     ddsdNewSprite.lHeight = bHeight                                         'Set the height of the surface
    11.     Set Sprite = dd.CreateSurfaceFromResource("", File, ddsdNewSprite)      'Load the bitmap from the resource file into the surface using the surface description
    12. [b]    CKey.low = ColourKey                                                    'Set the low value of the colour key
    13.     CKey.high = ColourKey                                                   'and the high value (in this case they're the same because we're not using a range)
    14.     Sprite.SetColorKey DDCKEY_SRCBLT, CKey                                  'Set the sprites colourkey using the key just created
    15. [/b]
    16. End Sub

    In bold is a little bit of the code that will help produce transparency. Now when you call it:

    VB Code:
    1. LoadSprite Ship(0).Surface(i), "vegan" & i, Ship(0).Width, Ship(0).Height, [b]vbBlack[/b]

    your image's background color that was in your bitmap file (Black) will be your source color key that you want transparent. If you want more choices in colors, here are some constants you can use to replace vbblack:

    VB Code:
    1. Public Const Transparent_Black As Long = &HFF000000
    2. Public Const Transparent_Red  As Long = &HFFFF0000
    3. Public Const Transparent_Green  As Long = &HFF00FF00
    4. Public Const Transparent_Blue  As Long = &HFF0000FF
    5. Public Const Transparent_Magneta As Long = &HFFFF00FF
    6. Public Const Transparent_Yellow As Long = &HFFFFFF00
    7. Public Const Transparent_Cyan As Long = &HFF00FFFF
    8. Public Const Transparent_White As Long = &HFFFFFFFF
    9.  
    10. 'or instead of a Hexadecimal value,
    11. 'use &HFF000000 + RGB(Red,Green,Blue)

    And when you blit it, one of the contsants you need to use is
    DDBLT_KEYSRC

    VB Code:
    1. BackBuffer.Blt DestRect, Ship(Current_Sprite).Surface(Ship(Current_Sprite).Facing), SrcRect, [b]DDBLT_KEYSRC[/b] Or DDBLT_WAIT

    If you want non transparent sprites, just add Transparency As Boolean into the Sprite type and do this when blitting:

    VB Code:
    1. If Ship(Current_Sprite).Transparency = True Then
    2.  
    3.      BackBuffer.Blt DestRect, Ship(Current_Sprite).Surface(Ship(Current_Sprite).Facing), SrcRect, [b]DDBLT_KEYSRC[/b] Or DDBLT_WAIT
    4.  
    5. Else
    6.  
    7.      BackBuffer.Blt DestRect, Ship(Current_Sprite).Surface(Ship(Current_Sprite).Facing), SrcRect, DDBLT_WAIT
    8.  
    9. End If


    There ya go. A nice easy and quick tutorial on Transparency using DirectX7.
    Last edited by Jacob Roman; Nov 30th, 2004 at 06:36 AM.

  17. #17

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256
    lol easy i wish, a little over my head there, lets go aside from the code i uploaded, how do i set the transparency when i load the image? In the surf=sprite line? or where?

  18. #18

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256
    Nevermind, I seem to have got it now

  19. #19
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Add resolved to the thread titile when it is resolved.......you just made me read through a LOOOONG thread, and it seems like all your questions are answered...



    PS: BltFast isn't that much faster on new GPUs. On hardware some years ago there was a big diffrence. But the new GPUs are more 3D based, and the HW vendors don't care that much about 2D anymore. So I don't think you will get that big boost by using BltFast.


    ØØ

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