DrawText as others have had, it's very strict with parameters, while working with font declarations I finally got it to work as expected, when I finally got it down to where the syntax worked, the program ran but didn't display text, I later found this to be because of the DrawTextFormat settings, some settings will render the font while others won't. I've moved onto other things and now I can't find the class I made to work with DrawText easier, but even when things were going well I realized DrawText was incredibly impacting my frame rates slowing down and not doing well with memory performance, and the more text displayed the worse it was so I went in search of an alternative and considered using a generated text mesh, and behold it works like a charm.Basically it's setup like this:'Global Variables. Private mesh3DText As Mesh = Nothing 'Mesh to draw 3d text. Private fontName As String = "Arial" 'Name of the font you wish to use. Private FontSize As Integer = 10 'Size of the font. Private textMaterial As Material 'Material to color text. Private matFont As Matrix = Matrix.Identity 'Matrix to position and scale. text. Private currentFont As System.Drawing.Font 'Variable that stores the font. 'Put this code where your Direct3D device is initialized.'Create a new font using the given parameters.. currentFont = New System.Drawing.Font(fontName, FontSize) 'Create 3D Text Mesh. mesh3DText = Mesh.TextFromFont(mobjDX9, currentFont, "This is a test message...", 0.001F, 0.4F) 'Create the material that will be used for the mesh. textMaterial = New Material textMaterial.AmbientColor = New ColorValue(0, 16, 180, 255) textMaterial.DiffuseColor = New ColorValue(0, 16, 180, 255)'Now put this in the render portion of the program to render the text. 'Set text mesh rotation. Dim matRot As New Matrix matRot.RotateYawPitchRoll(0, 0, 0) 'XYZ 'Set text mesh scale. Dim matScale As New Matrix matScale.Scale(5.0F, 5.0F, 1.0F) 'XYZ (Note: To change font depth change Z, a higher value will result in more 3D look while lower results in a flatter 2D look.) 'Set text mesh position. Dim matPos As New Matrix matPos.Translate(-20, -10, 0) 'XYZ 'Combine all matrix calculations. mobjDX9.Transform.World = Matrix.Multiply(Matrix.Multiply(matRot, matScale), matPos) mobjDX9.Material = textMaterial 'Set material for render. mesh3DText.DrawSubset(0) 'Render Mesh/DrawText. :cool: :D">
DirectX9.0c DrawText (Alternative)
Knight Chat X When I converted to DirectX 9.0c ran into the same problem with DrawText as others have had, it's very strict with parameters, while working with font declarations I finally got it to work as expected, when I finally got it down to where the syntax worked, the program ran but didn't display text, I later found this to be because of the DrawTextFormat settings, some settings will render the font while others won't. I've moved onto other things and now I can't find the class I made to work with DrawText easier, but even when things were going well I realized DrawText was incredibly impacting my frame rates slowing down and not doing well with memory performance, and the more text displayed the worse it was so I went in search of an alternative and considered using a generated text mesh, and behold it works like a charm. Basically it's setup like this: 'Global Variables. Private mesh3DText As Mesh = Nothing 'Mesh to draw 3d text. Private fontName As String = "Arial" 'Name of the font you wish to use. Private FontSize As Integer = 10 'Size of the font. Private textMaterial As Material 'Material to color text. Private matFont As Matrix = Matrix.Identity 'Matrix to position and scale. text. Private currentFont As System.Drawing.Font 'Variable that stores the font. 'Put this code where your Direct3D device is initialized. 'Create a new font using the given parameters.. currentFont = New System.Drawing.Font(fontName, FontSize) 'Create 3D Text Mesh. mesh3DText = Mesh.TextFromFont(mobjDX9, currentFont, "This is a test message...", 0.001F, 0.4F) 'Create the material that will be used for the mesh. textMaterial = New Material textMaterial.AmbientColor = New ColorValue(0, 16, 180, 255) textMaterial.DiffuseColor = New ColorValue(0, 16, 180, 255) 'Now put this in the render portion of the program to render the text. 'Set text mesh rotation. Dim matRot As New Matrix matRot.RotateYawPitchRoll(0, 0, 0) 'XYZ 'Set text mesh scale. Dim matScale As New Matrix matScale.Scale(5.0F, 5.0F, 1.0F) 'XYZ (Note: To change font depth change Z, a higher value will result in more 3D look while lower results in a flatter 2D look.) 'Set text mesh position. Dim matPos As New Matrix matPos.Translate(-20, -10, 0) 'XYZ 'Combine all matrix calculations. mobjDX9.Transform.World = Matrix.Multiply(Matrix.Multiply(matRot, matScale), matPos) mobjDX9.Material = textMaterial 'Set material for render. mesh3DText.DrawSubset(0) 'Render Mesh/DrawText. :cool: :D
Knight Chat XIn the last post it might be a little difficult to get font size accuracy settings just right, and the method works better for larger sized fonts or awkward fonts such as for a comic style game like Spiderman or Hulk where accuracy and a solid look is not an issue. Now if you want straight DrawText method I've come up with a simple class you can use, it contains basic size changes and 2D positioning which should be adequate for displaying text, the default font is Arial, feel free to modify the code to add more complicated font features. 'Simple DirectX 9.0c DrawText Class #Region "Imports" Imports Microsoft.DirectX Imports Microsoft.DirectX.Direct3D Imports Direct3D = Microsoft.DirectX.Direct3D #End Region Public Class clsDrawText #Region "Variables" Private customD3DFont As Microsoft.DirectX.Direct3D.Font Public fontName As String = "Arial" Public FontSize As Integer = 10 Private FontHeight As Integer = -10 #End Region #Region "Create New Font" Public Sub CreateFont(ByVal devD3DDevice As Device, Optional ByVal intFontSize As Integer = 10) FontSize = intFontSize FontHeight = -intFontSize customD3DFont = New Microsoft.DirectX.Direct3D.Font(devD3DDevice, FontHeight, 0, FontWeight.Bold, 1, False, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.DefaultPitch Or PitchAndFamily.FamilyDoNotCare, fontName) End Sub #End Region #Region "DrawText" Public Sub DrawText(ByVal strText As String, ByVal X As Integer, ByVal Y As Integer, ByVal col As Color) customD3DFont.DrawText(Nothing, strText, X, Y, col) End Sub #End Region End Class To Use: 'Put this in the global variables section of your main window. Private objDrawText As New clsDrawText 'Used for drawing text. 'Put this where your Direct3D device initialization code is. objDrawText.CreateFont(device) 'Create the font. (device is your Direct3D device.) 'Put this in the render section. objDrawText.DrawText("This is just a test message...", 1, 10, System.Drawing.Color.White) That's it, enjoy! [:D]
Eric ColemanThanks for posting that! You can also use the [ code ] tag so that the text is automatically formmated with the default colors.
salvapatuelthanks! I was having problems with DrawText clearing my sprites and flickering the screen sometimes. Your function just works :) thanks Salva