Would it be faster drawing lines using directX?
On the request of another user of these forums, would it be faster to use DirectX to draw 500,000 lines to the screen than a picturebox?
I helped him by showing him how to populate a UDT array from that huge file under 250ms which contains:
start x,y
end x,y
line color
line thickness
The problem is it takes 11 seconds to draw 500,000 lines to the picturebox on an athalon 1.5ghz machine....
I imagine it would be easier to write directly to video ram using directX.. Neither of us know how to program DirectX.. especially since a requirement is that the screen can be zoomed, and with a picturebox, that would mean refeeding all those values and redrawing those lines...
Here's the code so far:
VB Code:
Option Explicit
'User Defined Type below holds startxy, endxy, linecolor,linethickness
Private Type mapLineType
XPosStart As Single
YPosStart As Single
XPosEnd As Single
YPosEnd As Single
Colour As Long
Thickness As Single
End Type
'dim a UDT of size 500,000
Private mapLine(500000) As mapLineType
Private Sub Command1_Click()
Dim i As Long
Picture1.Scale (0, 0)-(7000, 7000)
'create some random test numbers
For i = 1 To 500000
mapLine(i).XPosStart = Int(7000 * Rnd + 1)
mapLine(i).YPosStart = Int(7000 * Rnd + 1)
mapLine(i).XPosEnd = Int(7000 * Rnd + 1)
mapLine(i).YPosEnd = Int(7000 * Rnd + 1)
mapLine(i).Colour = Int(31000 * Rnd + 1)
mapLine(i).Thickness = Int(2 * Rnd + 1)
Next
'save test numbers to file
Open ("C:\testfile.tst") For Binary As #1
Put #1, 1, mapLine
Close #1
MsgBox ("array populated and saved")
'load in test numbers
Open ("C:\testfile.tst") For Binary As #1
Get #1, 1, mapLine
Close #1
MsgBox ("loaded")
'draw test numbers
For i = 1 To 500000
Picture1.DrawWidth = mapLine(i).Thickness
Picture1.Line (mapLine(i).XPosStart, mapLine(i).YPosStart)-(mapLine(i).XPosEnd, mapLine(i).YPosEnd), mapLine(i).Colour
DoEvents
Next
MsgBox ("done")
End Sub
Here's the link to the original post...
http://www.vbforums.com/showthread.p...hreadid=198679
I would imagine anyone who uses DirectX regularly would have no problem changing this code... any help would be appreciated and given credit for...