Game Development Reference
In-Depth Information
Anotheroptionistodisplaytextorientedinthegameworld,thisoptioncanbeusedtolabel
the physical world without regard to the player's view direction.
Figure 48 - On the left, a screen aligned text label, on the right a world oriented text label.
Whicheverwaywechoosetodisplaythetext,thefirststepistobringthetextintoaformat
that can be mapped onto 3D geometry. One way to do this is to render the text into a tex-
ture, then create and transform a quad into the position and orientation desired and apply
the render target that contains the text as the quad's texture.
We will construct an object called text which we will use to render text in world space, the
first step will be to create a render target large enough to hold the text required. If the text
is static, meaning it will not change after construction, then the process is straightforward,
measure the size of the text to render and use its dimensions to create the render target. If
the text can change however, we cannot use the measured size as the size of the render tar-
get, it would need to be created to a specified maximum size, and any text that overflows
the render target would get clipped.
It is important to query the graphics device for the capability of creating non-power of two
textures, if the hardware does not support them, we will need to calculate the minimum
power of two size that will fit the text, this may lead to wasted texture space, we will see a
strategy for reusing texture space for text a bit later.
Rendering the text happens in two parts, the first part is rendering the text itself onto the
render target.
m_device->SetRenderTarget(m_renderTarget);
Search WWH ::




Custom Search