Sign in to follow this  
boxrick

D3D Font, over the top of a sprite?

Recommended Posts

I have a very simple question hopefully someone can provide me a decent answer to, googling seems to come up with nothing. I have a sprite and a D3DFONT ( LPD3DXFONT which i then create using D3DXCreateFont and draw ) it all works fine, but the problem is my text is never drawn ontop of the sprite, its always the text *below* the sprite. Without creating my own font class rather than using built in direct x one is there any solution to this? Is it possible to control the layers of what is drawn first in d3d a sprite or text?

Share this post


Link to post
Share on other sites
Do you End or Flush the sprite before you draw the font text?

sprite->Begin(...);
sprite->Draw(...);
sprite->End(...); // or sprite->Flush();
font->DrawText(...);

Share this post


Link to post
Share on other sites
I end my sprite rather than flush.

http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.directx.direct3d.sprite.flush.aspx

What sort of result will flushing have? Trying it in code seemed to make no real difference.

My classes for drawing text and sprites are called at different times between my render call but ordering ( fonts later ) seems to make no difference.

Share this post


Link to post
Share on other sites
Post your code for drawing the sprite and the text. I've tried to reproduce your problem, but, if I always draw the sprite first, followed by the text, it works fine.

Do you set the sprite position Z-value to 0? Don't think that makes a difference, but I haven't seen your code.

Share this post


Link to post
Share on other sites
After trying flush and doing some small swap around i have got it working! Thanks for your help, much appreciated.

Could you explain why flush affects the order of rendering?

Share this post


Link to post
Share on other sites
I'm not an expert on the internals, but I believe sprites don't render until End or Flush is called. Then they have their own way of deciding the order in which multiple draws (between Start/End) are rendered.

Even if you don't use the same sprite for the font->DrawText, the text will get rendered at the time of the font->DrawText call. Then, on sprite->End, it renders over the text.

Share this post


Link to post
Share on other sites
To add to this topic. Is there any way to control which texture is on which part of a layer other than the order they are loaded in?

Ie a way to change this once the texture has been loaded into the sprite?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this