Results 1 to 4 of 4

Thread: help with simple project, ASAP DX7

  1. #1

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    help with simple project, ASAP DX7

    I am going crazy, I wrote out the code JUST like I saw it on the site, I pasted it below, It says that the Set dd = dx.cReateDirectDraw("") line is not set (object not set or something about with block).. What is wrong with this? I am sure I missed 1 charecter or something.

    VB Code:
    1. ' ---Declarations--- '
    2. Option Explicit
    3. Dim binit As Boolean 'States weather we intialized or not.
    4. 'Also checks before drawing, If false, then we will get errors
    5. 'if we try to draw
    6.  
    7. Dim dx As DirectX7 'Root onject, everything comes from this
    8. Dim dd As DirectDraw7 'All directDraw **** is fr0m this
    9. Dim Mainsurf As DirectDrawSurface7 'This holds the BMP
    10. Dim primary As DirectDrawSurface7 'This replaces screen
    11. Dim backbuffer As DirectDrawSurface7 'This holds the BMP after to stop flickering
    12. Dim ddsd1 As DDSURFACEDESC2 'Describes surface
    13. Dim ddsd2 As DDSURFACEDESC2 'Describes BMP
    14. Dim ddsd3 As DDSURFACEDESC2 'Describes screen size
    15.  
    16. Dim brunning As Boolean 'Check wether or not the main gaMe loop is runnin
    17. Dim CurModeActiveStatus As Boolean 'Checks if we still have the correct display mode
    18. Dim bRestore As Boolean 'If we dont then we need to restOre the dispLay mode
    19.  
    20. ' ---mAiN--- '
    21. Sub Init()
    22.     'On Local Error GoTo errOut 'If an error occurs then leave
    23.    
    24.     Set dd = dx.DirectDrawCreate("") '() means default drivers
    25.     Me.Show 'Mazimises the form and makes it visibLe
    26.     'exclusive makes it so win pays more attention to this ap, and DirectDraw cant be used anywehre else
    27.     Call dd.SetCooperativeLevel(Me.hWnd, DDSCL_FULLSCREEN Or DDSCL_ALLOWMODEX Or DDSCL_EXCLUSIVE)
    28.     'First 3 are res and color settings, 4th is refresh rate and last is not needed
    29.     Call dd.SetDisplayMode(640, 480, 16, 0, DDSDM_DEFAULT) '1024x768 16bit Auto Refreshrate
    30.    
    31.     'Get screen surface and create bacKBuffer
    32.     ddsd1.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
    33.     ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
    34.     ddsd1.lBackBufferCount = 1
    35.     Set primary = dd.CreateSurface(ddsd1)
    36.    
    37.     'Get the backbuffer
    38.     Dim caps As DDSCAPS2
    39.     caps.lCaps = DDSCAPS_BACKBUFFER
    40.     Set backbuffer = primary.GetAttachedSurface(caps)
    41.     backbuffer.GetSurfaceDesc ddsd3
    42.    
    43.     'Init the surfaces
    44.     InitSurfaces
    45.    
    46.     'This is the main loop. It only runs when bRunnng is true
    47.     binit = True
    48.     brunning = True
    49.     Do While brunning = True
    50.         blt
    51.         DoEvents
    52.     Loop
    53.  
    54. errOut:
    55.     EndIt
    56. End Sub
    57.  
    58. Sub InitSurfaces()
    59.     Set Mainsurf = Nothing 'This must be cleared or we will get errors if we try to call this
    60.     'Load bmp into a surface
    61.     ddsd2.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH '
    62.     ddsd2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN 'Offscreenplain means teh uSer never sees anything, its just stored in memory
    63.     ddsd2.lWidth = ddsd3.lWidth 'Make the BMP size same as screen
    64.     ddsd2.lHeight = ddsd3.lHeight '^^ height
    65.     Set Mainsurf = dd.CreateSurfaceFromFile(App.Path & "\backdrop.bmp", ddsd2)
    66.     'First fill in ddsd2 and then use it to make a surface from a file, using DirectDraw
    67. End Sub
    68.  
    69. Sub blt()
    70.     On Local Error GoTo errOut 'If error, skip everything
    71.     If binit = False Then Exit Sub 'If not intiaised, then dont do anything DD related yet
    72.     Dim ddrval As Long 'Every drawing function returns a value, we will store it here and use it to check for errors
    73.     Dim rBack As RECT 'RECT is rectangLe.
    74.    
    75.     bRestore = False
    76.     Do Until ExModeActive = True
    77.         DoEvents
    78.         bRestore = True
    79.     Loop
    80.     'If we lost and got back the surfaces, lets restore htem
    81.     DoEvents
    82.     If bRestore = True Then
    83.         bRestore = False
    84.         dd.RestoreAllSurfaces 'Re allocates memory back to the surfaces, we still need to reload all of them tho -_-
    85.         InitSurfaces 'Must init surfaces again if we're lost
    86.     End If
    87.    
    88.     'Get area of screen where w1ndow is
    89.     rBack.Bottom = ddsd3.lHeight 'Set RECT to size of scrEEn
    90.     rBack.Right = ddsd3.lWidth
    91.    
    92.     'Make bmp appear over the window
    93.     ddrval = backbuffer.BltFast(0, 0, Mainsurf, rBack, DDBLTFAST_WAIT)
    94.     'Flip the backbuffer to the screen
    95.     primary.Flip Nothing, DDFLIP_WAIT
    96.     'we completed 1 cycle and can see something on screen
    97.    
    98. errOut:
    99.     'Dont put anything here, if game is at like 100 fps, the error will try show 100 times in 1 second :x
    100. End Sub
    101.  
    102. Sub EndIt()
    103.     'This runs on error or when we are done
    104.     'Restore back to default windows res
    105.     Call dd.RestoreDisplayMode
    106.     'tell dx and win that we no longer want exclusive access to directDraw
    107.     Call dd.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
    108.     End
    109. End Sub
    110.  
    111. Private Sub Form_Click()
    112.     EndIt 'do this if the user clicks screen, since its
    113.     'fullscreen mode the click location doesnt matter
    114. End Sub
    115.  
    116. Private Sub Form_Load()
    117.     Init 'main loop
    118. End Sub
    119.  
    120. Private Sub Form_Paint()
    121.     'If window needs painting run blt
    122.     blt
    123. End Sub
    124.  
    125. Function ExModeActive() As Boolean 'Check if were in correct res
    126.     Dim TestCoopRes As Long
    127.     TestCoopRes = dd.TestCooperativeLevel
    128.     If (TestCoopRes = DD_OK) Then
    129.         ExModeActive = True
    130.     Else
    131.         ExModeActive = False
    132.     End If
    133. End Function
    asdf

  2. #2

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    LMAO! I was missing the word 'new'! I just wasted like 2 hours!
    asdf

  3. #3
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Dim dx as New DirectX7? =)

    Z.

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Ah the joys of C++
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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