Jump to content
  • Advertisement
Sign in to follow this  
MikeMorcilla

Zenable text output

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I use D3DXCreateFont, DrawText function and one RECT to output text over a 3d scene. But text appears over any other object. I want text to be occluded by other objects. Anyone knows how to do this? If not, what do you use to output text in a 3d scene? (allowing zenable) Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
I only see one simple option. You could render the text to a texture, and then use the texture as a billboard in your scene. Otherwise, I don't really see what you can do to give an ID3DXFont interface depth.

Share this post


Link to post
Share on other sites
Billboarding makes it complicated, doesnt it?
If an object has a billboard label, that label must be scaled all the time to maintaing size if, for example, the object moves away...
There is no easier way or which one is the "best practice"?

Share this post


Link to post
Share on other sites
Once you render the text to a texture, you can use ID3DXSprite to render that texture into view. IIRC, the Sprite interface does have a z value you can set, and if the z-buffer is enabled - it should work as you want it to.

You are going to have to figure out the z value, and possibly the x and y values on your own.

Share this post


Link to post
Share on other sites
If you want to texture fonts onto in-game objects, you could just modulate the dynamically created font texture with the object's texture, if multi-texturing is an option. If you're doing something like I did a while back, making dialog windows with text on them, then you would just need to sort the windows, draw first window, then draw it's associated text, then draw the next window, it's text, etc. It's easy to sort the windows, because as the user clicks on them, they become the top level window, i.e. sorting done automatically. It sounds like you want to texture in-game objects that have perspective though, so I'd look into multi texturing and render to texture. If it's like an online game, where the characters have their names above their heads, you could still render to a texture, and render a 3D billboard with a position value same as the character mesh.

Good luck,
Chris

Share this post


Link to post
Share on other sites
Well, if you use your own ID3DXSprite interface when calling ID3DXFont::DrawText, you can make the text appear in 3D (or so I would imagine). Do the following:

mySpriteInterface->Begin(D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_BILLBOARD);

// Set any transforms to the device, as if you're transforming a regular 3D object

RECT r;

// Set the x and y of r to 0; hell, set all the members to 0 and use the
// DT_NOCLIP flag in DrawText()

myFontInterface->DrawText(mySpriteInterface, "hi", -1, &r, DT_NOCLIP, 0xFFFFFFFF);

mySpriteInterface->End();


That might work.

Share this post


Link to post
Share on other sites
Ok, tnaks a lot. Now I have ID3DXSprite working and drawing the text, but with:


g_pTextSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE);


If I use D3DXSPRITE_OBJECTSPACE or D3DXSPRITE_BILLBOARD, the text dissapears!

I've tried putting this before the "begin":

g_pTextSprite->SetWorldViewRH(&matWorld, &matView);

As it says so at the help files.

Also, I'm doing this transformation before DrawText:

g_pd3dDevice_text->SetTransform( D3DTS_WORLD, &matWorld );


And setting render state:

g_pd3dDevice_text->SetRenderState( D3DRS_ZENABLE, TRUE );


Then output text:

g_pFont[nFont]->DrawText( g_pTextSprite, pString, -1, &rc, DT_NOCLIP, D3DCOLOR_ARGB( g_nAlpha_text, g_nRed_text, g_nGreen_text, g_nBlue_text ));


But I cannot get it to work!
If I use (D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_BILLBOARD) text does not show.
If I use (D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE) text shows, but it is not zenabled!

Any advice please?




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!