3D Text, in a similar way to DrawTransform for a line

Started by
6 comments, last by REspawn 16 years, 8 months ago
Hi, im wondering if anyone has ever seen or knows if its possible to draw flat text in 3d space, kinda like a billboard only without it having to be a texture. Best example i can think of it the 3d line function drawtransform, and a visual example of what im trying to get would be metal gear solid's style of drawing the name of objects like below... thanks for any help, -Dave
Advertisement
What language are you using? Are you using ID3DXFont? If not, then it's just a case of drawing bilboarded quads, or scaled quads using an orthogonal projection matrix.
Since you most likely want to draw the text "5 pixels above an object" and not "2 world units above an object", it would make sense to do the drawing in screen-space after all.

What I do with things like this is get the position of the object I want to draw the text next to, offset by the amount I want (say, 5 pixels above the top of the bounding box) and then draw it at that screen position. This also allows me to handle cases where an object is too close to the top of the screen for the text to fit.

Hope this helps ;)
Sirob Yes.» - status: Work-O-Rama.
Im using c++ and im not using anything at the moment, im just looking into how i would go about creating the desired effect, cheers for the replys
Quote:Original post by REspawn only without it having to be a texture.
What does this mean?? The screenshot you give shows an effect that would most certainly be created using at least one 'texture'...
Quote:Original post by MasterWorks
Quote:Original post by REspawn only without it having to be a texture.
What does this mean?? The screenshot you give shows an effect that would most certainly be created using at least one 'texture'...


If you read it in context with the rest of the post you will see I make refrence to the DrawTransform function of a line and how it can be drawn without the need for a texture.

So to make it a bit clearer what it means is: Is it possible to draw text in 3D like in the screenshot without having to resort to using a texture.
This is my 3d space text drawing code (it's pretty simple):

void d3drenderer::rendertext3d(const std::wstring& text, const D3DXVECTOR3& p, unsigned long colour){	D3DVIEWPORT9 vp;	vp.X = 0;	vp.Y = 0;	vp.Width = width_;	vp.Height = height_;	vp.MinZ = 0.0f;	vp.MaxZ = 1.0f;	D3DXVECTOR3 textposition2d;	D3DXMATRIX w;	D3DXMatrixIdentity(&w);	D3DXVec3Project(&textposition2d, &p, &vp, &cache_proj, &cache_view, &w);	RECT rc;	rc.left = static_cast<long>(textposition2d.x);	rc.top = static_cast<long>(textposition2d.y);	rc.bottom = height_;	rc.right = width_;	font->DrawTextW( NULL, text.c_str(), -1, &rc, DT_NOCLIP, colour);}


Where font is an ID3DXFont*. Hope it helps.
Thats just the effect I wanted, thanks simonloach!

This topic is closed to new replies.

Advertisement