Results 1 to 18 of 18

Thread: Blitting Direct Draw?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Question Blitting Direct Draw?

    It will not draw my sprite. What did I do Wrong.

    Code:
    Dim DirectX As New DirectX7
    Dim DirectDraw As DirectDraw7
    'surfaces
    Dim PrimarySurf As DirectDrawSurface7
    Dim BackSurf As DirectDrawSurface7
    'Surface Descriptions
    Dim PrimarySDesc As DDSURFACEDESC2
    'Offscreen Surface
    Dim Sprt As DirectDrawSurface7
    
    Private Sub Form_Load()
        ChDir (App.Path) 
        
        Me.Show
        Me.WindowState = 2
        
        Init_DD
        
        LoadSprite "ball.bmp"
        
        DrawSprite
            
        PrimarySurf.Flip Nothing, DDFLIP_WAIT
        
    End Sub
    
    Sub Init_DD()
        Set DirectDraw = DirectX.DirectDrawCreate("")
        Call DirectDraw.SetCooperativeLevel(Me.hWnd, DDSCL_FULLSCREEN Or _
                                                     DDSCL_EXCLUSIVE Or _
                                                     DDSCL_ALLOWREBOOT)
                                    
        Call DirectDraw.SetDisplayMode(640, 480, 8, 0, DDSDM_DEFAULT)
        
        'Primary surface
        PrimarySDesc.lFlags = DDSD_BACKBUFFERCOUNT Or DDSD_CAPS
        
        PrimarySDesc.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or _
                                     DDSCAPS_FLIP Or _
                                     DDSCAPS_COMPLEX
        PrimarySDesc.lBackBufferCount = 1
        Set PrimarySurf = DirectDraw.CreateSurface(PrimarySDesc)
        
        'Back buffer
        Dim BackCaps As DDSCAPS2
        BackCaps.lCaps = DDSCAPS_BACKBUFFER
        Set BackSurf = PrimarySurf.GetAttachedSurface(BackCaps)
       
        BackSurf.SetForeColor vbWhite 'set font collor
        ClearBackBuffer
    End Sub
    Sub ShutDown()
        Set Sprt = Nothing
        Set PrimarySurf = Nothing
        Set BackSurf = Nothing
        Call DirectDraw.RestoreDisplayMode
        Call DirectDraw.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        ShutDown
    End Sub
    Public Sub DrawSprite()
        Dim SRect As RECT
        Dim DRect As RECT
        
        With SRect
            .Left = 0
            .Top = 0
            .Bottom = 64
            .Top = 64
        End With
        With DRect
            .Left = 0
            .Top = 0
            .Bottom = 64
            .Top = 64
        End With
        BackSurf.Blt DRect, Sprt, SRect, DDBLT_KEYSRC Or DDBLT_WAIT
    End Sub
    Public Sub LoadSprite(Path As String)
        Dim ddsd As DDSURFACEDESC2
        Dim ckey As DDCOLORKEY
        
        ddsd.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
        ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
        ddsd.lWidth = 64
        ddsd.lHeight = 64
        Set Sprt = DirectDraw.CreateSurfaceFromFile(Path, ddsd)
        ckey.high = vbBlack
        ckey.low = vbBlack
        Sprt.SetColorKey DDCKEY_SRCBLT, ckey
    End Sub
    Public Sub ClearBackBuffer()
        Dim BackRect As RECT
        With BackRect
            .Left = 0
            .Top = 0
            .Right = 640
            .Bottom = 480
        End With
        BackSurf.BltColorFill BackRect, 0
    End Sub

  2. #2
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hum... there are some things I don't get:

    1) Didn't VB give you an error in this line: "ChDir (App.Path)"? You shouldn't use brackets... it should be "ChDir App.Path"

    2) Anyway, you shouldn't be using ChDir. I'd do it this way:
    LoadSprite App.Path & "\ball.bmp"

    3) What error does it give you, and in what line?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Another thing (and this is probably your problem )

    You should use a "main loop". Your form_load sub should look like this:

    VB Code:
    1. Dim ExitProgram As Boolean
    2.  
    3. Private Sub Form_Load()
    4.     ChDir (App.Path)
    5.    
    6.     Me.Show
    7.     Me.WindowState = 2
    8.    
    9.     Init_DD
    10.    
    11.     LoadSprite "ball.bmp"
    12.    
    13.     Do Until ExitProgram
    14.         DoEvents
    15.        
    16.         DrawSprite
    17.        
    18.         PrimarySurf.Flip Nothing, DDFLIP_WAIT
    19.        
    20.         'Here you should check if the user pressed Escape or some key so you know when to set ExitProgram to True and the program exits.
    21.     Loop
    22. End Sub
    Last edited by Jotaf98; Jun 24th, 2001 at 07:47 AM.
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151
    The code does not give any erros, it does not draw the sprite and I don't know why.

    I didn't want to loop it yet I just wanted to flip the surface once so I can see the sprite. I draw boxes and text and stuff but I cant draw another surface.

    the chirdir since the brackets don't matter. since ther a space between method and the (. Its just an exprsion like
    a = (5)
    it dosen't matter if there a bracket around the 5 or not the value is still 5.

  5. #5
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Ok. Anyway, did you try to use a loop?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151
    if it didn't draw it once it wont draw it a hundred or a thousand times.

  7. #7
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    if it didn't draw it once it wont draw it a hundred or a thousand times.
    Dont be so sure about that man. Bill has his dirty fingers everywhere (PARANOIA)

    well I have another suspicion though
    see if the source rectangle is not a single rect bigger than the original picture, that you dont blit out of the window without a clipper. and try bltfast. In most cases it does the best (easiest) job.
    (sorry if you have a clipper or stuff i skimmed through your code very fast)
    Sanity is a full time job

    Puh das war harter Stoff!

  8. #8
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    hey uhm looked over it again.
    I can't say it is wrong, because I never tried it, but still it seems wierd, that you give the width and lenght width before loading the surface from a file. It seems very unecessary.

    good luck
    keep on trying
    Sanity is a full time job

    Puh das war harter Stoff!

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151
    Thats they way it was in the demo I was copying it from. I'm thinking I don't have a DD flag set right or I'm skipping a big step or something...

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151
    it still wont draw the sprite, even with a main loop. Something wrong with the Direct Draw code.

  11. #11
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Code:
        Do Until ExitProgram
            DoEvents
            
            DrawSprite
            
            PrimarySurf.Flip Nothing, DDFLIP_WAIT
            
            'Here you should check if the user pressed
               Escape or some key so you know when to set ExitProgram
               to True and the program exits.
        Loop
    <--- I hate that code!!!

    use this instead: (won't solv your problem but I had so say

    Code:
        While Not ExitProgram
            'Here you should check if the user pressed
               Escape or some key so you know when to set ExitProgram
               to True and the program exits.
            
            DrawSprite
            
            PrimarySurf.Flip Nothing, DDFLIP_WAIT
            DoEvents
        Wend
    Fox, who didn't ever use other loops than For and While

  12. #12
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    hey fox
    what is so good about while wend?
    isn't that a little outdated?
    Sanity is a full time job

    Puh das war harter Stoff!

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151
    For crying out loud I know how to do loops!

  14. #14
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I just hate the Do loops... and the Until of course... oh and not to forget the Loop statement *argh*

  15. #15
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    unless this is a typo your kick yourself for making a stupid mistake...

    Here is the code that is wrong
    Code:
        Dim SRect As RECT
        Dim DRect As RECT
        
        With SRect
            .Left = 0
            .Top = 0
            .Bottom = 64
            .Top = 64
        End With
        With DRect
            .Left = 0
            .Top = 0
            .Bottom = 64
            .Top = 64
        End With
    Notice anything wrong with it?

    it should be:
    [code]
    Dim SRect As RECT
    Dim DRect As RECT

    With SRect
    .Left = 0
    .Top = 0
    .Bottom = 64
    .Right = 64
    End With
    With DRect
    .Left = 0
    .Top = 0
    .Bottom = 64
    .Right = 64
    End With
    Some Days, i just get this feeling that i'm helping to write dozens of Viruses...

  16. #16
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Look Fox, that's a lame way to increase your post count...

    Try posting here your code *with the loop*. Maybe I'll be able to fix it

    You should read some tutorials on DX, maybe you forgot a flag or something...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  17. #17
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Congrats Nirces, I hadn't noticed that

    Of course it wouldn't blt: with a Right of 0... hehe I think something similar happened to me a while ago

    Sometimes these mistakes are good. You spend HOURS optimizing your code and then you find that little mistake... then you look at your old code and decide to use the new one that works much better
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Thumbs up

    Thank you very much. Now it works.

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