Text in d3d

Started by
1 comment, last by sipickles 17 years, 11 months ago
Okay, as many of you know i'm just learning d3d, converting some of my old [2d] work to the new libraries, and have come to text. Got a few ideas on how to excecute it, but am looking for advice from the pro's. Text appears for a short period, then disappears. First possible method : each letter is a textured quad in a dynamic vertex buffer, and they are kept track of by a text manager. I can render them all at the same time [one call, since all text fades at the same rate regardless of it's text length, all can be drawn in a single draw primitive call], but they take quite a bit of grunt work to make sure all the verteces stay where they should. Second method : each text bubble [collection of letters] is assembled onto a temporary texture, and the entire bubble is a single textured quad, that is rendered in a way similar to the above method. Maybe some neato method of doing things that i just haven't thought of... i'm open to suggestions and proposals. Any ideas? preferably with experience in this task : / Just for the sake of humor too, since I'd assume a number of you might find this pretty funny. The way I'm currently doing text, for test purposes and so i can have speech, even though i didn't implement the actual text render engine yet, is to have a windowed program running my game demos, and a console program running seperate, and the actual game demo sends the speech to the console window through socket communication :P. So in my console window, it keeps saying things like Unit, 'PC Player_1' Speaks : "I am injured!, help me!" Unit, 'NPC Helper_1' Speaks : "Confirmed" It's in real time, and is so darn funny that I might just have to keep it as an option.
Advertisement
Hi, yeah I'm not sure of what to do either, at the moment I'm bliting (ddraw style), characters from my font bitmap to the texture surface (this might be an offscreen surface), where they need to go, then using one of the stretch rect / update texture functions to update the actual texture on the screen.
so,

font bitmap/surface (in sysmem) -> blit to -> offscreen surface -> then update actual texture.

umm, I've actually inherited off the old d3dfont.h/cd3dfont class to get the font bitmap and all character tecxture coordinates.


The ways I'm actually using it are, (or some optimisations), for thngs which only need doing once such as labels etc, "print", the characters then you can release the font etc and just keep the labels texture. For edit boxes you would need to keep the font of course :p, also have an offscreen surface the same size as the edit box etc. For multiline things you would need to keep a bigger offscreen surface to allow for the lines (I think this is how d3dx font does it), but remember the previous lines can be updated as a block, they would already have been printed so don't print/blit them every time.

Any way I don't really know, I've just kinda been doing this on my own abit so I don't know what better/easier stuff there is.



Hi peach

I wrote my DX9 text library a while back, and I started doing the 'optimising' second approach, or something similar like Anon.

I had a single offscreen render target which I was filling with the various GUI features that were on the screen at the time, including text and window graphics etc. I was only updating 'dirty' portions. It was pretty complex.

After lengthy deliberation, I simplified matters and now just pump all the GUI textured quads into a dynamic vertex buffer, a la your first approach. I modified the SDK text sample so that it loads all my text font sizes and GUI graphics into a single texture, so no switching required, and one draw call. Also I can simply switch render order to stack the windows etc differently with no depth testing required.

Its easily fast enough, and a lot more versatile. the VB uses transformed vertices not hard to track.

Good luck!

Si

This topic is closed to new replies.

Advertisement