Results 1 to 9 of 9

Thread: Would it be faster drawing lines using directX?

  1. #1

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    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:
    1. Option Explicit
    2. 'User Defined Type below holds startxy, endxy, linecolor,linethickness
    3. Private Type mapLineType
    4.     XPosStart As Single
    5.     YPosStart As Single
    6.     XPosEnd As Single
    7.     YPosEnd As Single
    8.     Colour As Long
    9.     Thickness As Single
    10. End Type
    11.  
    12. 'dim a UDT of size 500,000
    13. Private mapLine(500000) As mapLineType
    14.  
    15. Private Sub Command1_Click()
    16. Dim i As Long
    17. Picture1.Scale (0, 0)-(7000, 7000)
    18.  
    19. 'create some random test numbers
    20. For i = 1 To 500000
    21. mapLine(i).XPosStart = Int(7000 * Rnd + 1)
    22. mapLine(i).YPosStart = Int(7000 * Rnd + 1)
    23. mapLine(i).XPosEnd = Int(7000 * Rnd + 1)
    24. mapLine(i).YPosEnd = Int(7000 * Rnd + 1)
    25. mapLine(i).Colour = Int(31000 * Rnd + 1)
    26. mapLine(i).Thickness = Int(2 * Rnd + 1)
    27. Next
    28.  
    29. 'save test numbers to file
    30. Open ("C:\testfile.tst") For Binary As #1
    31. Put #1, 1, mapLine
    32. Close #1
    33. MsgBox ("array populated and saved")
    34.  
    35. 'load in test numbers
    36. Open ("C:\testfile.tst") For Binary As #1
    37. Get #1, 1, mapLine
    38. Close #1
    39. MsgBox ("loaded")
    40.  
    41. 'draw test numbers
    42. For i = 1 To 500000
    43. Picture1.DrawWidth = mapLine(i).Thickness
    44. Picture1.Line (mapLine(i).XPosStart, mapLine(i).YPosStart)-(mapLine(i).XPosEnd, mapLine(i).YPosEnd), mapLine(i).Colour
    45. DoEvents
    46. Next
    47. MsgBox ("done")
    48. 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...

  2. #2
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    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

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    If you don't want to step to DX immediately you can also watch out for the LineTo API call...

  4. #4

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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...

  5. #5
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    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

  6. #6

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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...

  7. #7
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    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

  8. #8

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Thanks for the reply, I will wait for the original author to respond to see if DirectX is something he's willing to implement...

  9. #9
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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
  •  



Click Here to Expand Forum to Full Width