Jump to content
  • Advertisement
Sign in to follow this  
braveocean

How to render text in world space just like the text above people's head in the game

This topic is 4490 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

How to render text in world space just like the text above people's head in the game of world of warcraft? is it just same like "Render to Surface" to create a texture with text ,then map on a quad? or there is another efficiency way? thank's a lot!

Share this post


Link to post
Share on other sites
Advertisement
you could transform the point above the characters head to screenspace(project it) and use that coord to draw a usual 2D-Text there.

Share this post


Link to post
Share on other sites
you could write your text to a surface and use that in a texture on a screen aligned quad...?

havent done it myself but its possible

Share this post


Link to post
Share on other sites
Quote:

you could transform the point above the characters head to screenspace(project it) and use that coord to draw a usual 2D-Text there.



This seems like the best way to go, as long as you don't care if the text doesn't interact correctly with geometry (ie., if a character walks behind a wall and you can no longer see him, you will still see text above his head - but this could be solved by determining first if the character is unobscured.)

I do pretty much the same thing in my own game, printing text above entities such as each entity's ID number, or whatever. What I do is use a GetScreenPoint() function which takes a point in 3d space and returns a point in screenspace. I get the screen position of my entity and then call my print function to output text at (returned_position.x-xoffset,returned_position.y-yoffset).

Of course, this may or may not work depending on what you mean by having text "above" a character's head. Does "above" mean above along the y axis on the screen or on the y axis in the world? (Those two may be more or less the same thing, depending on where your camera is.) If the latter, you would probably want to tweak the values of xoffset and yoffset per camera orientation so that they always print text in the right direction away from your character.

Here's my GetScreenPoint function, for reference:


D3DXVECTOR2 GetPoint(D3DXVECTOR3 point, const D3DXMATRIX* mscreen_pnt)
{
//return the screen point of a point in 3dimensions
D3DXVECTOR3 v1;
D3DXVECTOR2 screenpoint;

D3DXVec3TransformCoord(&v1, &point, mscreen_pnt);
v1.x=((v1.x+1.0f)/2.0f);
v1.y=((v1.y+1.0f)/2.0f);
screenpoint.x=v1.x*800;
screenpoint.y=600-v1.y*600;
return screenpoint;
}




where mscreen_pnt is defined elsewhere thus:

D3DXMATRIX mscreen_pnt;

D3DXMATRIX m_view;
D3DXMATRIX m_world;
D3DXMATRIX m_proj;
d3ddevice->GetTransform(D3DTS_VIEW,&m_view);
d3ddevice->GetTransform(D3DTS_WORLD, &m_world);
d3ddevice->GetTransform(D3DTS_PROJECTION, &m_proj);
m_screen_pnt=m_world*m_view*m_proj;





I hope that this can help you out.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!