Hello everyone. I have been trying to make a font renderer that uses freetype for the past couple of days but am currently stuck with getting uv tex values when rendering.
Here is the current code I use
struct SVertex
{
SVector4f pos;
Color32 col;
SVector2f tex;
};
// D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1
float CDisplayFont::DrawTextA( const char * szText, int textCount, const SVector2f& pos, const SColor & color, const SRectf * pClipRect )
{
SVector2f tmp = ( pos );
IRender * pRender = g_pCore->GetGraphics()->GetRender();
for ( int i = 0; i < textCount; ++i )
{
Codepoint_t cp = static_cast< Codepoint_t >( szText[ i ] );
if ( GlyphInfo_t * info = GetGlyphInfo( cp ) )
{
if ( szText[ i ] != ' ' )
{
float sx = tmp.x + info->offsetX * m_fScaleHoriz;
float sy = tmp.y - ( info->height - info->offsetY ) * m_fScaleVert;
float w = info->width * m_fScaleHoriz;
float h = info->height * m_fScaleVert;
// column (u) and row (v) number
// -- heres where i'm stuck
float u = 0;
float v = 0;
SVertex vtx[ ] =
{
{ sx, sy + h, 0.0f, 1.f, color, u, v },
{ sx, sy, 0.0f, 1.f, color, u, v },
{ sx + w, sy + h, 0.0f, 1.f, color, u, v },
{ sx + w, sy, 0.0f, 1.f, color, u, v },
{ sx + w, sy + h, 0.0f, 1.f, color, u, v },
{ sx, sy, 0.0f, 1.f, color, u, v }
};
// arguments -> ( rl, vtx data, vtx count, topology, texture (IDirect3DTexture9) )
pRender->PushVertices( NULL, vtx, 6, D3DPT_TRIANGLELIST, info->texture->GetInternalPtr() );
}
tmp.x += ( float )( info->advance >> 6 ) * m_fScaleHoriz;
}
}
return tmp.x;
}
This obviously prints nothing because I am stuck on how exactly I should be getting the correct u & v coords.
I have confirmed that I am getting the correct texture by saving the IDirect3DTexture9 to a file, getting stuff like this - https://imgur.com/a/Lwl2Xws
I appreciate any advice/pointers in the right direction, thank you.