Problem displaying text with Direct3D 8

Roy Lazarovich
03-31-2002, 02:52 PM
Hello

I've been having a lot of problems displaying text on my DirectX surface, I am able to display the text, but on some computers the program crashes with an "out of memory" error.

This is my code:

in sub Main():

If Engine.DisplayFPS Then

TextRect.Top = 0
TextRect.Left = 0
TextRect.bottom = 20
TextRect.Right = 70

fnt.Bold = False
fnt.Italic = False
fnt.Name = "Arial"
fnt.Size = 8
fnt.Strikethrough = False
fnt.Underline = False

Set MainFont = d3dx.CreateFont(Device, MainFontDesc.hFont)

d3dx.DrawText MainFont, &HFFFFFFFF, "FPS: " & Game.FPS, TextRect, DT_TOP Or DT_LEFT

Set MainFont = Nothing

End If

in the D3DStart function:

Set MainFontDesc = fnt

in the general declarations:

Private MainFont As D3DXFont ' DirectX font device
Private MainFontDesc As IFont ' Font object
Private TextRect As RECT ' Rectangle information
Private fnt As New StdFont ' Standard font object


I would be very happy if you could send me a small code example of how to display text in a correct way so as not to cause errors.

Thank you very much

Squirm
03-31-2002, 03:10 PM
Here is a snippet from some DX code I have lying around:



Dim CurrentFontX As D3DXFont
Dim CurrentFont As New StdFont
Dim CurrentColor As Long

Dim FontDesc As IFont

With CurrentFont
.Name = FontName
.Size = FontSize
.Bold = True
.Italic = True
End With

Set FontDesc = CurrentFont
Set CurrentFontX = D3DX.CreateFont(Device, FontDesc.hFont)

CurrentColor = &HFF0000FF

Dim RecDest As RECT

With RecDest
.Top = 100
.Left = 100
.bottom = (CurrentFont.Size * 2) + 100
.Right = (CurrentFont.Size * Len("Hello World!") * 2) + 100
End With

D3DX.DrawText CurrentFontX, CurrentColor, "Hello World!", RecDest, DT_LEFT Or DT_TOP


I'm sure you can pick something useful out of that code. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum