Game Development Reference
In-Depth Information
for ( auto& txt : worldSpaceTextList )
{
textBatch.Add(txt, rtWidth, rtHeight);
}
TheAddfunctionwillmeasurethescreenspaceextentsofthetextandinsertarectangleof
that size into the BSP, if successful, we will calculate the UV coordinates for that node and
use them to calculate the x,y position into the render target into which we will render the
text.
void text::Add(const std::wstring& txt, size_t rtWidth, size_t rtHeight)
{
auto size = m_font->MeasureString(txt.c_str());
auto& node = bsp.Insert(rectangle(0, 0, size.x, size.y);
if ( node != nullptr )
{
auto uv = bsp.TextureCoordinates(node);
float x = uv.x() * rtWidth;
float y = uv.y() * rtHeight;
m_font->DrawString(m_spriteBatch.get(), txt.c_str(), math::vector2(x,y), render::color::WHITE, 0);
}
}
At this point there is only one thing missing, we still need to render the actual world space
text, and we need to do so using the same UV coordinates that we have just used to store
ourtextintotherendertarget.Inordertodothis,wewillneedtoextendthequadprimitive
to support UVs to be provided at render time, this can be done by modifying the vertex
shader to receive scaling and bias parameters to remap the existing UVs.
Search WWH ::




Custom Search