|
-
Sep 15th, 2002, 11:30 AM
#1
Thread Starter
I wonder how many charact
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...
-
Sep 15th, 2002, 11:41 AM
#2
Lively Member
U need DirectX alright, lol at 11 seconds
DirectX has its own functions which u will need to learn to do wot u wanna do. Heres a great sight if u can be bothered to learn DirectX
www.directx4vb.com
Dan
PS With DirectX you can draw 1000's of line 50 times every second and zooming with directx is very easy.
I recommend u read up on lessons 1,3,4 and 5 to do wot u wanna do although the rest is good as well, it just goes into deeper stuff
-
Sep 15th, 2002, 11:45 AM
#3
PowerPoster
If you don't want to step to DX immediately you can also watch out for the LineTo API call...
-
Sep 15th, 2002, 12:21 PM
#4
Thread Starter
I wonder how many charact
I implemented the LineTo API, but that does not operate any faster than VB's native .Line function....
As far as DirectX calls... I was really looking for someone who could post code that implements the above data variables...
-
Sep 15th, 2002, 01:14 PM
#5
Lively Member
Wiv DirectX u dont just have a line function and stuff like that. First u have to initialise a whole set of objects (which needs some understanding) and then u can draw stuff. The initialisation code is quite lengthy so it is not potssible to give u 1 line of code that will draw a line, u have to know how to initialise DirectX first and then u can use its power. Thats why i recommended the site. If u dont learn it then u may as well forget the speed that directX has to offer. Your call.
Dan
-
Sep 15th, 2002, 01:38 PM
#6
Thread Starter
I wonder how many charact
Its not the initialization of the DirectX objects that has me frustrated, it seems rather straight forward to me... more if this direction would actually realize any benefit in speed.
I guess I would ask this question:
The program requirement needs to load this information in Windowed Mode, and display it in a picturebox (from what I ascertained from the site u posted, this is a good container for a directX surface).
But the best way for the program to run would be to load this information into video ram, so it can be zoomed, and perhaps rotated... without resending the data.
In essence, I need a way to blit the array data onto a DirectX drawing surface...
I thank you for directing me to the directx4vb website, but it does not help answer what methods should be used to accomplish a task such as above, which is why I am still asking...
-
Sep 15th, 2002, 02:01 PM
#7
Lively Member
Well as far as I can make out (Im not great with terminology), you want to render stuff in a pic box. I am 99% sure this is possible (I think anything with an .hwnd property can be used as a drawing surface). During the initialisation stage basically u would store the line data. This data can then be rendered as it is. Moreover, with two simple lines of code such as
D3DXMatrixRotationY MatrixName, Angle * radians
D3DDevice.SetTransform D3DTS_WORLD, MatrixName
You can rotate the lines without having to replot the points.
Many similar things can be done without recalculating the data such as scaling and translation (moving).
Hope this helps and hope I wasnt too rude in last letter
Dan
PS Believe me DirectX is worth the effort, when u use it u wont look back
-
Sep 15th, 2002, 02:24 PM
#8
Thread Starter
I wonder how many charact
Thanks for the reply, I will wait for the original author to respond to see if DirectX is something he's willing to implement...
-
Sep 15th, 2002, 04:48 PM
#9
Frenzied Member
You cannot use the desktop as a rendering target, but pretty much anything else will do... I have used the start button, as well as the main start bar thing as targets... It is amusing, to say the least...
Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|