Artanis Posted November 20, 2004 Posted November 20, 2004 (edited) I'm writing a game file editor that draws a graphical representation of the file to a screen, so the user can see what he's 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? Here's what I have now. I haven't modified it for stuff I learned about when I found this place yesterday, like paint events. 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 doesn't 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. Edited November 20, 2004 by Artanis Quote
ThePentiumGuy Posted November 20, 2004 Posted November 20, 2004 Lines - I'm pretty sure you can do that in DirectX, althoug Don't 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 Tutor's Corner on this. Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Artanis Posted November 20, 2004 Author Posted November 20, 2004 (edited) Lines - I'm pretty sure you can do that in DirectX, althoug Don't 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 Tutor's Corner on this. The reference files say there's a line funtion, but for some reason the place it's supposed to be, D3DX, is not there. I think I found your clsText. 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. I'm so confused. These things are supposed to be there, but they aren't. :confused: Edited November 20, 2004 by Artanis Quote
ThePentiumGuy Posted November 20, 2004 Posted November 20, 2004 You have an older version of DirectX (oh btw, for D3Dx, did you remember to add it's 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 don't 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 Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Artanis Posted November 20, 2004 Author Posted November 20, 2004 (edited) I don't 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. Edited November 20, 2004 by Artanis Quote
Knight Chat X Posted November 20, 2004 Posted November 20, 2004 Looks more like the bare GDI+ library, which is probably why it doesn't show up in DirectX references. To answer the question, yes you can draw lines, circles, and other things in DirectX, it's 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 you'd use more than likely, create 2 points for both ends of a line and draw the line between both points. Here's DrawPrimitive: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_vb/directx_vb/graphics/reference/vb/d3d/classes/direct3ddevice8/drawprimitive.asp And you can see here you there is a line list as an option: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_vb/directx_vb/graphics/reference/vb/d3d/classes/direct3ddevice8/drawprimitive.asp :D Quote
Artanis Posted November 21, 2004 Author Posted November 21, 2004 The DrawPrimitive method is what you'd use more than likely' date=' create 2 points for both ends of a line and draw the line between both points.[/quote'] I think I'm doing something wrong, cause I'm not getting errors, but I'm not getting a line when I run it either. I attatched the project sans exe (I've been modifying ThePentiumGuy's tutorial to get this to work, rather than clutter my project.) Here's DrawPrimitive: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_vb/directx_vb/graphics/reference/vb/d3d/classes/direct3ddevice8/drawprimitive.asp And you can see here you there is a line list as an option: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_vb/directx_vb/graphics/reference/vb/d3d/classes/direct3ddevice8/drawprimitive.asp :D Are those two urls supposed to be identical?DirectXTest.zip Quote
ThePentiumGuy Posted November 21, 2004 Posted November 21, 2004 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 they're the same. Well dude, are you in vs2003 or vs2002? Tell me the version number to your DLL's (when you go to Add|Reference, it'll say it). If you have 9.<something>.0<something> then it's A, if you have 9.<something>.2902 or 2904 then it's 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 don't you simply have a bitmap as a circle and scale it as needed? Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Artanis Posted November 21, 2004 Author Posted November 21, 2004 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 they're the same. Well dude, are you in vs2003 or vs2002? Tell me the version number to your DLL's (when you go to Add|Reference, it'll say it). If you have 9.<something>.0<something> then it's A, if you have 9.<something>.2902 or 2904 then it's 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 don't you simply have a bitmap as a circle and scale it as needed? vs2003, windows2000 Are you sure it's 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.) I'll 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. Quote
ThePentiumGuy Posted November 21, 2004 Posted November 21, 2004 oh, whoops, I guess it starts with a 1 :P. Sorry man, I can't help you there.. I gotta get the october update :D i din't know they had one! Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Artanis Posted November 21, 2004 Author Posted November 21, 2004 oh, whoops, I guess it starts with a 1 :P. Sorry man, I can't help you there.. I gotta get the october update :D i din't know they had one! Alright. I thought I was doing something wrong and getting v1 of DirectX SDK or something. :eek: I'm gonna go reinstall the october update now. And DirectX isn't what I'd expect someone to notice being updated.' Anyway. Still pretty sure I'm doing something wrong trying to draw lines. Quote
Joe Mamma Posted November 22, 2004 Posted November 22, 2004 ummm. . . why not forget the directx. draw to a bitmap then copy the composed bitmap onto the graphic???? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
ThePentiumGuy Posted November 22, 2004 Posted November 22, 2004 Oh, well to draw lines.. first take a look at my drawintg sprites tutorial. This time use a linelist to draw 2 points to make a line... Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
ThePentiumGuy Posted November 22, 2004 Posted November 22, 2004 I think jay1b's right. DirectX is overkill for your project :D. See if you can find a way to optimzie with GDI+ here's 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) Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Artanis Posted November 25, 2004 Author Posted November 25, 2004 I think jay1b's right. DirectX is overkill for your project :D. See if you can find a way to optimzie with GDI+ here's 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. I'll look for ways to optimize GDI+, then. Thanks for your help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.