Too much to draw! Can I do this in DirectX?

Artanis

Member
Joined
Nov 19, 2004
Messages
7
Im writing a game file editor that draws a graphical representation of the file to a screen, so the user can see what hes doing, instead of guessing. I have to redraw this everytime something is changed. This will entail ~75,000 draw commands when everything is being drawn. It runs fine on my P4, but tends to lock slower computers for an unreasonable amount of time.


Is it possible to have DirectX draw things without using sprites? Can I tell it to draw circles, lines and text?


Heres what I have now. I havent modified it for stuff I learned about when I found this place yesterday, like paint events.
Code:
    Public Sub DrawGalaxy()
        Dim i, j As Integer
        Dim pF As PointF
        Dim rF As RectangleF
        Dim Draw As System.Drawing.Graphics
        Dim SystemFill As New System.Drawing.SolidBrush(System.Drawing.Color.Black)
        Dim SystemOutline As New System.Drawing.Pen(System.Drawing.Color.White, 1)

        pnlMap.Refresh()
        Draw = pnlMap.CreateGraphics()

        If Prefs.HighQuality = True Then
            Draw.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        Else
            Draw.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed
        End If

        draw nebulae above or below grid?
        draw grid here

        draw hyperlinks
        If Prefs.Hyperlinks.Draw = True Then
            Dim Hyper As New System.Drawing.Pen(Prefs.Hyperlinks.drawColor, 1)
            Dim SelColor As System.Drawing.Color = Color.FromArgb(128, Prefs.SelectedLinks.drawColor)
            Dim Sel As New System.Drawing.Pen(SelColor, 5)

            For i = 0 To Systems.Length - 1
                If Systems(i).bDraw = True Then
                    For j = 0 To 15
                        If Systems(i).Hyperlink(j) <> -1 Then
                            If Systems(Systems(i).Hyperlink(j) - 128).bDraw = True Then
                                Dim Start, Dest As PointF

                                Start = Transform_Point(Systems(i).Position, pnlMap)
                                Dest = Transform_Point(Systems(Systems(i).Hyperlink(j) - 128).Position, pnlMap)

                                Draw.DrawLine(Hyper, Start, Dest)

                                If lstSystems.SelectedIndex <> -1 Then
                                    If Get_Index(lstSystems.SelectedItem) = i Then
                                        Draw.DrawLine(Sel, Start, Dest)
                                    End If
                                End If
                            End If
                        End If
                    Next
                End If
            Next
        End If
        Draw Wormholes
        Draw Hypergates
        Draw Systems
        For i = 0 To Systems.Length - 1
            If Systems(i).bDraw = True Then
                convert absolute position to account for zoom and
                translation and container coordinates (0,0 doesnt want to be the top, left)
                pF = Transform_Point(Systems(i).Position, pnlMap)
                pF.X -= Prefs.GetSystSize / 2
                pF.Y -= Prefs.GetSystSize / 2
                create rectangle bounds for ellipse
                rF = New RectangleF(pF, Prefs.SystSize)
                draw
                Draw.FillEllipse(SystemFill, rF)
                Draw.DrawEllipse(SystemOutline, rF)
            End If
        Next i
        Draw labels
        If Prefs.SystemLabel.Draw = True Then
            Dim Text As New System.Drawing.SolidBrush(Prefs.SystemLabel.drawColor)
            For i = 0 To Systems.Length - 1
                If Systems(i).bDraw = True Then
                    pF = Transform_Point(Systems(i).Position, pnlMap)
                    pF.X += Prefs.GetSystSize
                    pF.Y += Prefs.GetSystSize
                    Draw.DrawString("(" & Systems(i).ID & ") " & Systems(i).Name, _
                                    Prefs.MapFont, _
                                    Text, _
                                    pF)
                End If
            Next
        End If
    End Sub

Any help is greatly appreciated.
 
Last edited by a moderator:
Lines - Im pretty sure you can do that in DirectX, althoug Dont quote me.
Circles - damn. beats me... look into Direct3D.SPrite (or is it DirectX.Sprite), it might have someothing
Text - for sure. I posted a text class somewhere on the forum.

Look into www.vbprogramming.8k.com (my site) or my tutorials on the Tutors Corner on this.
 
ThePentiumGuy said:
Lines - Im pretty sure you can do that in DirectX, althoug Dont quote me.
Circles - damn. beats me... look into Direct3D.SPrite (or is it DirectX.Sprite), it might have someothing
Text - for sure. I posted a text class somewhere on the forum.

Look into www.vbprogramming.8k.com (my site) or my tutorials on the Tutors Corner on this.
The reference files say theres a line funtion, but for some reason the place its supposed to be, D3DX, is not there.

I think I found your clsText.
Code:
    Public Class clsText

        Dim TheFont As Microsoft.DirectX.Direct3D.Font = Nothing

        Dim rect As New Rectangle(0, 0, 0, 0)

        Dim x As Microsoft.DirectX.Direct3D.font

        Dim y As Microsoft.DirectX.Vector3

        Dim s As Microsoft.DirectX.Direct3D.Sprite

        Public Sub New(ByVal d3ddev As Microsoft.DirectX.Direct3D.Device, Optional ByVal fontname As String = "Courier", _
        Optional ByVal Size As Integer = 10)

            TheFont = New Microsoft.DirectX.Direct3D.Font(d3ddev, New System.Drawing.Font(fontname, Size))

            s = New Microsoft.DirectX.Direct3D.Sprite(d3ddev)

        End Sub

        Public Sub Drawtext(ByVal text As String, ByVal cColor As System.Drawing.Color)

            s.Begin(Microsoft.DirectX.Direct3D.SpriteFlags.AlphaBlend)
            TheFont.DrawText(s, text, 0, 0, cColor)
            s.End()
        End Sub
    End Class
The Direct3D.Sprite, .Font, and .SpriteFlags are errored as not being members of Direct3D/not defined in .Net, yet msdn shows them in Direct3D here.

Im so confused. These things are supposed to be there, but they arent. :confused:
 
Last edited by a moderator:
You have an older version of DirectX (oh btw, for D3Dx, did you remember to add its reference?). Look at the Intro tutorial for more info, you have to manually add the references if you have .net 2002.

Manually add the references from: C:\WINDOWS\Microsoft.NET\Managed DirectX\v9.02.2904

You actually dont need the sprite, the sprite is required in DX 9.0c. So delete any word that says sprite, and you might have to change the TheFont.DrawText arguments a bit.

-The Pentium Guy
 
I dont think my DirectX is older. I just installed it Friday, said Oct 04 update.

It needed a reference to Direct3DX, which is close enough to D3DX for me. I have a feeling a bunch of things were renamed.

Just tested clsText, now looking into lines and circles.
 
Last edited by a moderator:
Looks more like the bare GDI+ library, which is probably why it doesnt show up in DirectX references.

To answer the question, yes you can draw lines, circles, and other things in DirectX, its a little more complicated though, try seeing some of the tutorials in the SDK, paticularly the Vertices Triangle Example, you may also do some searching on how to draw basic primitive shapes online, Microsoft provides some information related to this in the MSDN library for DirectX.

The DrawPrimitive method is what youd use more than likely, create 2 points for both ends of a line and draw the line between both points.

Heres DrawPrimitive:
http://msdn.microsoft.com/archive/d...d3d/classes/direct3ddevice8/drawprimitive.asp

And you can see here you there is a line list as an option:
http://msdn.microsoft.com/archive/d...d3d/classes/direct3ddevice8/drawprimitive.asp

:D
 
Knight Chat X said:
The DrawPrimitive method is what youd use more than likely, create 2 points for both ends of a line and draw the line between both points.
I think Im doing something wrong, cause Im not getting errors, but Im not getting a line when I run it either. I attatched the project sans exe (Ive been modifying ThePentiumGuys tutorial to get this to work, rather than clutter my project.)

Knight Chat X said:
Are those two urls supposed to be identical?
 

Attachments

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/e/primitivetype/primitivetype.asp
<-- For DX9, although theyre the same.

Well dude, are you in vs2003 or vs2002? Tell me the version number to your DLLs (when you go to Add|Reference, itll say it). If you have 9.<something>.0<something> then its A, if you have 9.<something>.2902 or 2904 then its C.

Oh yeah! KnightChat... yeah i totally forgot about that (that you can use TriangleStrip/List...etc) To make a circle, it would have to be really complicated (LOTS of vertices). Why dont you simply have a bitmap as a circle and scale it as needed?
 
ThePentiumGuy said:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/e/primitivetype/primitivetype.asp
<-- For DX9, although theyre the same.

Well dude, are you in vs2003 or vs2002? Tell me the version number to your DLLs (when you go to Add|Reference, itll say it). If you have 9.<something>.0<something> then its A, if you have 9.<something>.2902 or 2904 then its C.

Oh yeah! KnightChat... yeah i totally forgot about that (that you can use TriangleStrip/List...etc) To make a circle, it would have to be really complicated (LOTS of vertices). Why dont you simply have a bitmap as a circle and scale it as needed?
vs2003, windows2000

Are you sure its supposed to start with a 9? I had the october update (1.02.3900.0), uninstalled it and installed the Summer update to check, 1.02.2902. The folders they were in started with 9s (v9.02.3900.0 and v9.02.2904, repsectively.)

Ill just use GDI+ to draw a circle on a transparent bitmap at runtime, since the size can be set by the user, and use it as a texture. Scaling something like that would look horrible.
 
ThePentiumGuy said:
oh, whoops, I guess it starts with a 1 :P.
Sorry man, I cant help you there.. I gotta get the october update :D i dint know they had one!
Alright. I thought I was doing something wrong and getting v1 of DirectX SDK or something. :eek:
Im gonna go reinstall the october update now.

And DirectX isnt what Id expect someone to notice being updated.

Anyway. Still pretty sure Im doing something wrong trying to draw lines.
 
I think jay1bs right. DirectX is overkill for your project :D. See if you can find a way to optimzie with GDI+

heres what I do:
Override OnPaint (and put nothing in the sub) - trust me it helps
Me.SetStyle(controlstyles.allpaintinginWMpaint Or controlstyles.UserPaint Or controlstyles.DoubleBuffer,true)
 
ThePentiumGuy said:
I think jay1bs right. DirectX is overkill for your project :D. See if you can find a way to optimzie with GDI+

heres what I do:
Override OnPaint (and put nothing in the sub) - trust me it helps
Me.SetStyle(controlstyles.allpaintinginWMpaint Or controlstyles.UserPaint Or controlstyles.DoubleBuffer,true)

Done and Done.
Ill look for ways to optimize GDI+, then.
Thanks for your help.
 

Similar threads

Back
Top