Jump to content
  • Advertisement

Archived

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

MagTDK

Text with Direct3D

This topic is 5653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a text class that I've created using D3D to draw text to the screen. The problem is, I find my application takes a substantial hit in fps when I have alot of text on the screen. This obviously has to do with the way my class works so I'll give you a run down of what I'm doing. During initialization I load my font texture that has all the characters on it and then create a finite sized dynamic vertex buffer that will be used to hold the vertices of my characters polygons. When it comes time to render my text, I first set my texture stage to my font texture, then lock and unlock my dynamic vertex buffer so I can add a polygon associated with that character in my string. I do this so I can set the position of each characters polygon. Then lastly, I render that character to the frame buffer. This is done for each character in my text string. This locking and unlocking is were I believe my slow down is happening. Unfortunately the only other way I can think of doing this would be to create a static vertex buffer with the number of polygons that equal the total number of characters I can possible use. For instance, in my application this would be ASCII characters (32-127). Then when it comes time for rendering my text, all I do is set the world transformation for that character in order to place it in it's proper position on the screen. But this method would require me to call the SetTransform function of D3D for each character in my text string. First I'd like to ask if anyone has a better way of doing this? Second question. Is it faster to call the SetTransform function of D3D for each character or stay with what I'm alreading doing and that is locking and unlocking my vertex buffer for each character? [edited by - MagTDK on March 30, 2003 9:57:41 AM]

Share this post


Link to post
Share on other sites
Advertisement
2nd one first: I have no idea. It shouldn''t matter though, read on:

Are you using screen-space coordinates or world space coordinates? My engine uses transformed (screen-space) coords, so I don''t even have to deal with transformation matrices.

In any case, the way I''ve found that works best is to create a static vertex buffer of some reasonable length (mine happens to hold 1024 characters, I think), copy the vertex data of each character of whatever string you want to draw to the buffer, and then draw the whole thing in one fell swoop. Plus you only have to lock the buffer once for the whole string.

Email me if you want my code: ewalt@comcast.net

Share this post


Link to post
Share on other sites
I''m using world space coordinates.

The problem is, I''m doing this for my console class so my text strings are created on the fly depending on what the user types in.

Share this post


Link to post
Share on other sites
What Holy Fuzz said (almost): Lock a dynamic (not static) vertex buffer and fill it with all of the vertices, then unlock it and draw all the characters in one DrawPrimitive call.

Yes locking and unlocking the VB for each character is going to be slow. In addition calling DrawPrimitive with only one or two triangles is practically guaranteed to give you poor performance.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!