Option Explicit
'determines performance of execution for testing purposes only
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
Private Type mapLineType
XPosStart As Single
YPosStart As Single
XPosEnd As Single
YPosEnd As Single
Colour As Long
Thickness As Single
End Type
Private mapLine(500000) As mapLineType
'below type is needed for LineTo and MoveEx API functions
Private Type POINTAPI
x As Long
y As Long
End Type
Private DX7 As New DirectX7
Private DD7 As DirectDraw7
Private Primary As DirectDrawSurface7
Private Back As DirectDrawSurface7
Public Display As Form1
Private Sub InitialiseDirectX()
Dim ddsd As DDSURFACEDESC2, Size As RECT
Dim Clip As DirectDrawClipper
'Instantiate the main DX DirectDraw
Set DD7 = DX7.DirectDrawCreate("")
'Negotiate a normal windowed display
DD7.SetCooperativeLevel Display.hWnd, DDSCL_NORMAL
'Create the primary surface used to display completed images
ddsd.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
Set Primary = DD7.CreateSurface(ddsd)
'Create and attach a Clipper to the Primary surface
Set Clip = DD7.CreateClipper(0)
Clip.SetHWnd Display.hWnd
Primary.SetClipper Clip
'Create a back surface used to compose images before display
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.lWidth = Display.ScaleWidth
ddsd.lHeight = Display.ScaleHeight
Set Back = DD7.CreateSurface(ddsd)
End Sub
Public Sub cleanup()
'Reset the display back to the original windows
DD7.RestoreDisplayMode
'Release objects
Set DX7 = Nothing
Set DD7 = Nothing
Set Back = Nothing
Set Primary = Nothing
Unload Form1
Set Form1 = Nothing
End Sub
Public Sub main()
Dim mypointapi As POINTAPI
Dim EmptyRect As RECT, DestRect As RECT
Dim i As Long
'needed for conversion from twips to pixels with API functions
Dim picture1width As Long
Dim picture1height As Long
'performance measuring variable
Dim start As Long
Set Display = New Form1
Display.ScaleMode = vbPixels
'Setup and initialise the DX environment and the Vectoid population
InitialiseDirectX
Form1.Show
picture1width = (Form1.Width / Screen.TwipsPerPixelX)
picture1height = (Form1.Height / Screen.TwipsPerPixelY)
'make some RANDOM DATA
For i = 1 To 500000
mapLine(i).XPosStart = Int(picture1width * Rnd)
mapLine(i).YPosStart = Int(picture1height * Rnd)
mapLine(i).XPosEnd = Int(picture1width * Rnd)
mapLine(i).YPosEnd = Int(picture1height * Rnd)
mapLine(i).Colour = Int(10000 * Rnd + 1)
mapLine(i).Thickness = Int(1 * Rnd + 1)
Next
Open ("C:\testfile.tst") For Binary As #1
Put #1, 1, mapLine
Close #1
'Begin load and draw
start = GetTickCount
Open ("C:\testfile.tst") For Binary As #1
Get #1, 1, mapLine
Close #1
Debug.Print "loaded in : " & (GetTickCount - start) / 1000 & " seconds"
start = GetTickCount
'clear the back surface
Back.BltColorFill EmptyRect, vbBlack
'draw the lines to the back surface
For i = 1 To 500000
Back.SetForeColor mapLine(i).Colour
Back.DrawLine mapLine(i).XPosStart, mapLine(i).YPosStart, mapLine(i).XPosEnd, mapLine(i).YPosEnd
Next
'Get the latest size and position of destination window
DX7.GetWindowRect Display.hWnd, DestRect
'Blt the back surface to the primary surface
Primary.Blt DestRect, Back, EmptyRect, DDBLT_WAIT
Debug.Print "Drawn in :" & (GetTickCount - start) / 1000 & " seconds"
End Sub