Game Development Reference
In-Depth Information
m_spriteBatch->Begin(DirectX::SpriteSortMode_Deferred);
{
m_font->DrawString(m_spriteBatch.get(), m_text.c_str(), math::vector2::Zero, m_color, 0);
}
m_spriteBatch->End();
m_device->ResetRenderTarget();
We set the device's active render target to the one we created and we then render the text
into it, we render it to the position 0,0 which means it will be rendered onto the renter tar-
get's top left corner. After we have finished drawing, we reset the device's render target to
its default, the frame buffer.
At this point, we have a texture in memory that contains the text we rendered in it, so we
can render a quad and apply this render target as its texture. We can now decide how we
want to draw the quad, whether it will be world oriented or screen aligned.
For a world oriented quad, in addition to the world space position of the text, we can
provide a direction vector, a normal. Given a normal, we will call it the forward vector,
wecan create the worldoriented transformation matrix toapply tothe quadasdescribed in
World Oriented Quad.
forward = m_normal;
forward.Normalize();
right = forward.Cross(vector3::UnitY);
up = right.Cross(forward);
transform = matrix::Create(right, up, forward, m_position);
If we wish the text to be screen aligned, we can toggle the ViewAlign flag on the quad ob-
ject (see Screen Aligned Quad ) and we then only need to provide a matrix with the trans-
lation.
if ( m_viewAlign )
{
m_quad->ViewAlign() = true;
transform = math::matrix::CreateTranslation(position);
}
Finally we call the Draw function for the quad and we pass the desired transform and we
use the render target that we created.
m_quad->Draw(transform, view, projection, m_renderTarget);
One thing to consider when rendering in-world geometry, is whether we want it to write its
depth data or not, for screen-aligned text, we don't want to write into the depth buffer, this
would cause text to get depth sorted, possibly intersecting with the world's geometry as its
Search WWH ::




Custom Search