Sign in to follow this  
utilae

How to get mouse to render above text?

Recommended Posts

Hi I am using C++ and Direct3D9. Since text has no z value, I am drawing text after rendering all gui polygons from my vertex buffer. My only problem is that in order for the mouse to appear to overlap text, I have to draw the mouse seperately on it's own, eg Add vertices for gui polygons Draw Primitive Draw Text for each bit of text. Add vertices for mouse Draw Primitive (only for 6 vertices) This is obviously such a waste. Is the some better way. Like to draw text so that it has a z value and can have a render order, so that I can mix it in with polygons.

Share this post


Link to post
Share on other sites
Text is no different than any other D3D element... are you using a D3DX helper? Text is drawn with vertices/textures just like anything else, so my guess is that if you're using an outside library to help you're going to lose the ability to batch your text in with your other GUI needs.

That being said, your comment "such a waste" has got to be overblown. If adding the vertices for the mouse and rendering them (separately) is any kind of performance bottleneck for you, then you have some serious other problems.

My advice is to ignore stupid little problems like this unless they matter. If your entire GUI drawing system is only a couple of DrawPrimitive batches you are doing just fine.

If you really had to do this all in one go, you would put both your GUI elements, your text, and your mousecursor graphics all in one massive texture. Then just add your vertices (back to front) and render, right? That would be hard to do without your own text engine.

Share this post


Link to post
Share on other sites
I'm using ID3DXFont. I know it can be used with ID3DxSprite, is that how it could be drawn at a certain z level. Otherwise how would I make my text get sent to the vertex buffer.

Share this post


Link to post
Share on other sites
Have you considered using hardware cursor support?

Take a look at the SDK documentation for IDirect3DDevice9::SetCursorProperties and IDirect3DDevice9::SetCursorPosition.


If you're performing any kind of scene sorting, as you need to when using alpha transparency, then the mouse cursor sprite could be treated exactlty like everything else, except with a high sort key which ensures it always ends up last in the scene.


I do agree with MasterWorks though, the waste of treating the cursor differently to other things in your scene is so insignificant in terms of both development time and runtime performance that it's not worth worrying about.

Share this post


Link to post
Share on other sites
Quote:
Original post by utilae
SO if I call draw primitive for only one primitive it won't be that bad on performance.


No, that will be fine for performance (assuming there isn't a different bottleneck with that primitive - which for a "normal" game style mouse cursor there won't be).

The common [and good] advice about batching to reduce the number of Draw*Primitive calls is generally about your whole scene - it's saying "don't draw every sprite/mesh in your game with a separate draw call if at all possible". Sometimes you simply can't avoid a new draw call.

If the rest of your scene is batched well, then a [small] few single sprite draw calls won't hurt. Generally if you aim to keep the number of draw calls per-frame in the low 100s, you can expect good performance and adding a single one for the cursor won't hurt at all.

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