Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 DirectX9.0c DrawText (Alternative)

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
Knight Chat X Posted - Nov 20 2004 : 2:23:49 PM

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
6   L A T E S T    R E P L I E S    (Newest First)
VBBR Posted - May 28 2005 : 5:54:38 PM
Cool, Almar's still alive

That remembers me... I need to talk to you about YALG... like how much success did it have?

I think I have the solution for YALG to be widespread
Almar Posted - May 28 2005 : 4:52:26 PM
Hm, I'd like to point out that DX9 has some kind of caching option. The CustomUI sample uses it, and keeps the FPS high. I ported the CustomUI sample to DX8, which lacked that option. Therefore I got poor performance.

I think it buffers the ext on a sprite object or so.
Knight Chat X Posted - May 20 2005 : 01:41:45 AM
It's been awhile since I made this post but I forgot to mention that one cool thing is that you can re-use the DrawText method to render multiple modified versions of the text without needing to create more objects, you can create the font object once then do multiple renders, for example:

I want text to show at 1,10 with the color of white:
objDrawText.DrawText("This is just a test message...", 1, 10, System.Drawing.Color.White)

Ok, but now I want to draw different text in another place in a different color but using the same object:
objDrawText.DrawText("This is another test message...", 1, 50, System.Drawing.Color.Green)

The same concept can be used for normal mesh objects, if I'm correct, the ability to re-use objects like this could save resources, as you can make modifications to an already loaded object that only displays the changes on a per render basis without requiring loading extra copies into memory, the effect is desired changes are seen visually on display but not done internally. Maybe like a brush!
salvapatuel Posted - Dec 15 2004 : 3:59:08 PM
thanks!

I was having problems with DrawText clearing my sprites and flickering the screen sometimes.

Your function just works :)

thanks
Salva
Eric Coleman Posted - Nov 23 2004 : 11:10:10 AM
Thanks for posting that! You can also use the [ code ] tag so that the text is automatically formmated with the default colors.
Knight Chat X Posted - Nov 23 2004 : 01:47:25 AM
In 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!



VBGamer © Go To Top Of Page
This page was generated in 0.16 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.