D3DXFONT always on top

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

Recommended Posts

Hi, I have just finshed my GUI (screenpolys and D3DXFONT). The problem is that when I launch a window covering the rest of the GUI, the window covers pixels drawn earlier but not the font. Text is always visible no matter when or what I draw to cover it. Imagine a screen full of lists, checkboxes, labels, etc. A widow appears, it covers all the gui elements, but all the texts are written on it... It looks terrible. Is D3DXFONT::DrawText(...) rendering onto a separate surface which is added on top of polygon rendering just before Present(...)? How do I avoid that? (But please don't tell me I have to make my own fonts from textures... ;-) ) Thanks Bartiss

Share on other sites
Hi there bartiss,
How are you doing?

The Problem
Font is always ontop.

The Solution
Simple solution would be just to render the font when needed. This just means that when you bring up this window... stop rendering the font in the background ;)

Other than that... yep I would think that it be best to create your own textured font system which might be a nice touch but I know it's not the route you want to go. Might be simpler in the long run ;)

I hope this helps buddy.
Take care.

Share on other sites
Try rendering the fonts without a sprite object, see if that works. There's some wonky aspects of D3DXFont, but it's got beautifull unicode support that (almost) makes up for it.

In your case, I assume that D3DX is caching the rendering-operation, and then flushing it at a later draw-call. By rendering it without a sprite object (or by manually flushing the sprite), things should get better.

Allan

Share on other sites
You can control the depth at which your UI text draws something like this:

pSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT);...D3DXMATRIX xform;D3DXMatrixTranslation(&xform, 0.0f, 0.0f, depth);pSprite->SetTransform(&xform);pFont->DrawText(pSprite, ...);...pSprite->End();

Setting the sprite transform will effect everything you draw subsequently with that sprite object. So when you draw the sprites for your other UI widgets, you'll probably want to specify 0 for the z-value of their position. And 'depth' should be a value between 0 and 1.

Also, make sure you are using the latest DXSDK. They just added the ability to specify both D3DXSPRITE_SORT_TEXTURE and D3DXSPRITE_SORT_DEPTH_BACKTOFRONT at the same time in the last update.

xyzzy

Share on other sites
Thanks xyzzy00 !

I wasn't using sprites, but now when I set the depth of drawing the font I have everything I need! It works as I wanted it to!

Thanks again
Bartiss

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 9
• Forum Statistics

• Total Topics
633331
• Total Posts
3011390
• Who's Online (See full list)

There are no registered users currently online

×