• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Speed of LPD3DXFONT

## Recommended Posts

I just wrote a class that works with the LPD3DXFONT Direct X class. Although I have just ran into a problem, speed. When I print out just the fps in 800x600x32 I get about 600-800fps. When I print out just 7 more variables the FPS slows to about 300-400!! Does anyone have any idea what I am doing wrong, by the way I am calling the text like this:

LPD3DXFONT->Begin();
LPD3DXFONT->DrawText(idents[i], -1, &fontRect, DT_CALCRECT, 0);
LPD3DXFONT->DrawText(idents[i], -1, &fontRect, DT_LEFT, D3DCOLOR_XRGB(255, 50, 50));

...

LPD3DXFONT->End();

[edited by - HunterTKilla on October 20, 2002 1:16:32 PM]

##### Share on other sites
There are many shortcommings to D3DXFont. The one I read of most often is it uses the Windows GDI to create the text, which is never good when speed is key. You''re only going to get about two to three lines of text before taking massive performance hits.

----
AIDS

##### Share on other sites
The SDK comes with D3DFont in the Common source which is many times faster than D3DXFont.

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
I can confirm this, I have been using D3DXFont for some basic output stuff, and it is *slow*. I''ll have to look into what Drunken Hyena is talking about.

##### Share on other sites
I also have a custom library that does text rendering. It used a bitmap which I prefer to a Windows font.

http://www.drunkenhyena.com/docs/dhFastFont.phtml

Full source, it''s just a header file.

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
Definitely check out DrunkenHyena''s technique. It''s a lifesaver.

----
AIDS

##### Share on other sites
Argh, I just got finished working D3DXFont into my textbox/listitem class hierarchy. I really wanted to be able to set the rectangle for clipping so I could chop text to a certain length in text boxes etc.

Neither CD3DFont nor DH''s implementation do this...

Anyone looked into extending CD3DFont to clip (especially the width) to a rectangle yet? Hmmm...

##### Share on other sites
quote:
Original post by Igilima
Anyone looked into extending CD3DFont to clip (especially the width) to a rectangle yet? Hmmm...

yup.

##### Share on other sites
the ID3DXFont class isn''t for rendering directly to the screen. Well, it is if you dont care about speed. But if you do care about speed, then its for rendering to a texture.

use the ID3DXFont class to render the alphabet to a texture, then parse the letters of the texture, and go from there.

The problem with the DH font tutorials is that all the fonts have to be pre-generated with a separate program. You can use ID3DXFont to generate them programmatically at load time, or on-the-fly.

##### Share on other sites
quote:
Original post by PSioNiC
use the ID3DXFont class to render the alphabet to a texture, then parse the letters of the texture, and go from there.

##### Share on other sites
niyaw, I downloaded that text display code and tried to integrate it but it gave me all kinds of compile errors starting with the ''<'' in this line:
typedef CComPtr IDirect3DTexture8Ptr;

Is that your text display code?

I tried compiling the fontdemo and it told me it couldn''t find stdafx.h even though that was right there in the project directory. I put in the full path for the include line and then stdafx.h complained that it couldnt find atlapp.h I am guessing that I don''t even have that on my drive but I the search for it is going in the background.

Anyway, I may try to get that working again later since the cd3dbitmapfont has a bunch of functionality I want in a font. I think one of the problems is that that font may have too much functionality if that is possible. :oP

So right now I am extending CD3DFont just to add the few features I think I need right away.
I am inheritting a class called CD3DFontEx from CD3DFont and will be adding clipping to a rectangle and perhaps centering etc.

One problem I found with CD3DFont that is really strange is this. On my laptop (Radeon 7500, 32MB RAM) the text has randomish pixels missing from it! This problem doesn''t show up on any of my desktops (Radeon 7500, TNT2, GeForce3). Anyone know why my laptop is having trouble showing all the pixels in the text displayed by CD3DFont???

##### Share on other sites
quote:
Original post by Igilima
niyaw, I downloaded that text display code and tried to integrate it but it gave me all kinds of compile errors starting with the ''<'' in this line:
typedef CComPtr IDirect3DTexture8Ptr;

you need to include headers from stdafx.h for the .h/.cpp files to compile. CComPtr is the COM smart pointer class that takes care of calling AddRef and Release when needed.
quote:

Is that your text display code?

part of it
quote:

I tried compiling the fontdemo and it told me it couldn''t find stdafx.h even though that was right there in the project directory.

project settings must have messed up.

I put in the full path for the include line and then stdafx.h complained that it couldnt find atlapp.h

you need to grab WTL here. copy the contents of the include folder in the archive to one of your include directories (no files should be overwritten), or make a separate directory for it and add it to the include directories in msvc options.

apparently, i need to provide better installation instructions.
quote:

Anyway, I may try to get that working again later since the cd3dbitmapfont has a bunch of functionality I want in a font. I think one of the problems is that that font may have too much functionality if that is possible. :oP

i like to say that my font provides functionality of GDI at the speed of CD3DFont
quote:

One problem I found with CD3DFont that is really strange is this. On my laptop (Radeon 7500, 32MB RAM) the text has randomish pixels missing from it! This problem doesn''t show up on any of my desktops (Radeon 7500, TNT2, GeForce3). Anyone know why my laptop is having trouble showing all the pixels in the text displayed by CD3DFont???

got a screenshot? are you using italic/fancy fonts by any chance? gettextextentpoint32, which cd3dfont uses, doesn''t support italics and truetype underhangs/overhangs, which will produce what you''re describing.

##### Share on other sites
Me again... :o)

I've got a modified CD3DFont doing the basics for me but I want to spend as little time as possible reinventing the wheel.

I got the WTL library and got your font demo to compile. It still gave me over a dozen warnings but at least it runs. The reason my compiler couldn't find stdafx.h in the fontdemo project was because it likes to have \\ instead of \ in a path.

The text displayed by your font class also has the same pixel problems I saw in CD3DFont on my laptop. Sorry I don't have a screenshot for you yet. What shall I use? PrintScreen button? I will work at getting one for you if you are really really interested in seeing it. Basically the letters will have some pixels missing from them and then there will be pixels in the font color sprinkled around the letters here and there.

As I mentioned before, I had problems compiling your .h file into my project because it didnt like CComPtr in the following line:
typedef CComPtr 'IDirect3DTexture8' IDirect3DTexture8Ptr; I put ' where < belongs because it keeps thinking I am trying to do html formatting.

Here is the error:
c:\projects\common\d3dbitmapfont.h(7) : error C2143: syntax error : missing ';' before '<'

It doesnt like CComPtr. Is there a .h file I have to include in order to get CComPtr to work in your .h?

Is all I need to use this font the .cpp and .h files?

[edited by - Igilima on October 27, 2002 8:47:51 PM]

##### Share on other sites
quote:
Original post by Igilima
I got the WTL library and got your font demo to compile. It still gave me over a dozen warnings but at least it runs. The reason my compiler couldn''t find stdafx.h in the fontdemo project was because it likes to have \\ instead of \ in a path.

i fixed the thing up a bit so that it doesn''t require WTL anymore. and as i was wondering about some stuff, i discovered that the demo you downloaded was pretty old. i updated the font class, but never got around to refreshing the demo zip file. you can get the newest stuff here.
quote:

The text displayed by your font class also has the same pixel problems I saw in CD3DFont on my laptop.

now that i realized that you had an old version of the font, what you''re experiencing may fall in the "known issues" category. please download the latest code and see if the problem is still present; it shouldn''t be.
quote:

Sorry I don''t have a screenshot for you yet. What shall I use? PrintScreen button?

yup, printscreen should work.
quote:

I will work at getting one for you if you are really really interested in seeing it.

if the new code doesn''t fix the problem, i''d very much appreciate a screenshot along with your LOGFONT structure and test string, if possible.
quote:

Basically the letters will have some pixels missing from them and then there will be pixels in the font color sprinkled around the letters here and there.

this sounds like some weird stuff i had and should''ve fixed.
quote:

As I mentioned before, I had problems compiling your .h file into my project because it didnt like CComPtr in the following line:

you need to include <atlbase.h>.
quote:

I put '' where < belongs because it keeps thinking I am trying to do html formatting.

use html tags: &lt;

thanks for taking time to deal with me.

##### Share on other sites
quote:
Original post by PSioNiC
The problem with the DH font tutorials is that all the fonts have to be pre-generated with a separate program.

That''s like saying that normal textures are bad because you need to pre-generate them with a separate program. I guess we should just use Perlin noise for all our textures.

I wrote the library that way specifically because I don''t want to use TTF fonts. If I want a custom font, I''d have to get a TTF builder and figure out how to generate one. No thanks.

With a pre-made font texture, your font becomes part of the game art. If all you need it for is an FPS counter or debugging info, then it really doesn''t matter.

In one of my demos I have nicely bevelled fonts with a drop shadow, do that with CD3DFont.

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
quote:
Original post by Igilima
Argh, I just got finished working D3DXFont into my textbox/listitem class hierarchy. I really wanted to be able to set the rectangle for clipping so I could chop text to a certain length in text boxes etc.

Neither CD3DFont nor DH''s implementation do this...

No mine doesn''t do this. I never needed it. The source isn''t very big, and it''d be easy to add if you wanted to.

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
quote:
Original post by DrunkenHyena
In one of my demos I have nicely bevelled fonts with a drop shadow, do that with CD3DFont.

##### Share on other sites
quote:
Original post by niyaw

This one has a bevelled font. Keep in mind that I'm not an artist, so someone with talent could make it look a lot better.

I haven't released the one with the drop shadow, but you can load one of the font images into an art package, add one, save and you're done. dhFastFont will use whatever alpha is in the source image, so you can do cool things.

At some point I want to do a custom tool to make creating the fonts a bit easier. But for now it does what I need.

I tried to find some artists to put together sample fonts and release a little 'FontToy' demo to show off a variety of them, but it's hard to find people with talent working for free.

The next version of Doodle Invaders (out soon I hope) uses a custom font that looks scribbly. Again, something I couldn't do with D3DFont.

Stay Casual,

Ken
Drunken Hyena

[edited by - DrunkenHyena on October 28, 2002 3:29:45 AM]

##### Share on other sites
niyaw, your new fontdemo code isnt a visual studio project. :o(

I tried creating a new project and added all the .h, .cpp and .rc files.

My compiler didn''t like the CString class in porting.h
c:\projects\fontdemo\porting.h(16) : error C2614: ''CString'' : illegal member initialization: ''string'' is not a base or member

##### Share on other sites
i upgraded to vs.net, therefore my new project has vc7 project/solution files. you can probably use the project file from the old code; the only thing you need to do is remove d3dbitmapfont.* and readd them, because they are now in the same directory as all other files. unfortunately, the old project had messed up precompiled header settings, so if you still get errors, try disabling precompiled headers everywhere. i''ll try to get ahold of msvc6 tomorrow and make a project file for it.

##### Share on other sites
msvc6 project is up

• ### Forum Statistics

• Total Topics
627741
• Total Posts
2978887

• 10
• 10
• 21
• 14
• 14