Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Troubles with DirectDraw in VB

This topic is 5722 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The sprites don''t show up when called and stuff. I''m not sure why.... This is part of a DLL plugin for the Microsoft Script Control if that helps. Also I''m making a mini-scripting language. Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''DirectX7 ''Programmed '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''Main Variables Dim DX As New DirectX7 Dim DD As DirectDraw7 ''Surfaces Dim Primary As DirectDrawSurface7 Dim BackBuffer As DirectDrawSurface7 ''Description Dim dPrimary As DDSURFACEDESC2 Dim dBackBuffer As DDSURFACEDESC2 ''Clipper Dim ddClipper As DirectDrawClipper ''Rects Dim BufferRect As RECT Dim PrimaryRect As RECT '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''Declarations ''Programmed '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Running As Boolean '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''Engine Core ''Programmed '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function Init(Width As Long, Height As Long, Caption As String) As Boolean On Error GoTo Failed frmMain.Show frmMain.Caption = Caption ''frmMain.picBox.Width = Width ''frmMain.picBox.Height = Height ''frmMain.ScaleWidth = frmMain.picBox.Width ''frmMain.ScaleHeight = frmMain.picBox.Height ''Init DDraw Set DD = DX.DirectDrawCreate("") ''Set Cooperative Level Call DD.SetCooperativeLevel(frmMain.hWnd, DDSCL_NORMAL) ''Setup Primary Surfaces dPrimary.lFlags = DDSD_CAPS dPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Set Primary = DD.CreateSurface(dPrimary) ''Setup BackBuffer dBackBuffer.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT dBackBuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY dBackBuffer.lWidth = 320 dBackBuffer.lHeight = 240 Set BackBuffer = DD.CreateSurface(dBackBuffer) DX.GetWindowRect frmMain.picBox.hWnd, BufferRect DX.GetWindowRect frmMain.picBox.hWnd, PrimaryRect ''Setup Clippers Set ddClipper = DD.CreateClipper(0) ddClipper.SetHWnd frmMain.picBox.hWnd Primary.SetClipper ddClipper Running = True Exit Function Failed: MsgBox "Engine Failed to Initialize Direct Draw.", vbCritical, "GCDS Runtime Error" End Function Public Function Force_Render() On Error GoTo Failed Dim ddResult As Long ddResult = Primary.Blt(PrimaryRect, BackBuffer, BufferRect, DDBLT_WAIT) Exit Function Failed: MsgBox "Failed to Force Render due to an Error.", vbCritical, "GCDS Runtime Error" End Function Public Function Clear() On Error GoTo Failed Dim FillRect As RECT Dim ddResult As Long With FillRect .Top = 0: .Left = 0 .Right = 320: .Bottom = 240 End With ddResult = BackBuffer.BltColorFill(FillRect, 0) Exit Function Failed: MsgBox "Failed to Clear Screen due to an Error.", vbCritical, "GCDS Runtime Error" End Function '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''Engine Drawing Functions ''Programmed '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Sprites'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function LoadSprite(Filename As String, Width As Long, Height As Long) As DirectDrawSurface7 On Error GoTo Failed Dim dTemp As DDSURFACEDESC2 dTemp.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT dTemp.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN dTemp.lWidth = Width dTemp.lHeight = Height Set LoadSprite = DD.CreateSurfaceFromFile(Filename, dTemp) Exit Function Failed: MsgBox "Failed to Load Sprite.", vbCritical, "GCDS Runtime Error" End Function Public Function Render_Sprite(Sprite As DirectDrawSurface7, X As Long, Y As Long, Width As Long, Height As Long) On Error GoTo Failed: ''Has it been initialized? If not let''s get out of this procedure If Running = False Then Exit Function ''Some local variables Dim ddrval As Long Dim r2 As RECT ''The bitmap size ''Sprite Rect r2.Left = X r2.Top = Y r2.Right = X + Width r2.Bottom = Y + Height ''Using Blt instead of Bltfast is essential - do not try and use bltfast. ''The advantage of using blt is that it resizes the picture to be the same as ''the picture box, this means that we can resize the window and the code ''will adapt to fit the new size - even though it will look really ugly ''when stretched. ddrval = BackBuffer.Blt(BufferRect, Sprite, r2, DDBLT_WAIT) Force_Render Exit Function Failed: MsgBox "An Error Occured While Rendering the Sprite", vbCritical, "GCDS Runtime Error" End Function Do you like skateboarding? I sure do!!!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!