How to get mouse to render above text?

Started by
5 comments, last by utilae 18 years, 10 months ago
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.

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

Advertisement
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.
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.

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

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.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

SO if I call draw primitive for only one primitive it won't be that bad on performance.

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

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.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Oh, ok. I only have like 3 draw primitive calls so far. Basically I plan to have one draw primitive call per texture.

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

This topic is closed to new replies.

Advertisement