18 #include "precompiled.h"
44 proj.
SetOrtho(0.f, (
float)
g_xres, 0.f, (
float)g_yres, -1.f, 1000.f);
85 wchar_t buf[1024] = {0};
89 int ret = vswprintf(buf,
ARRAY_SIZE(buf)-1, fmt, args);
93 debug_printf(L
"CTextRenderer::Printf vswprintf failed (buffer size exceeded?) - return value %d, errno %d\n", ret, errno);
101 wchar_t buf[1024] = {0};
105 int ret = vswprintf(buf,
ARRAY_SIZE(buf)-1, fmt, args);
109 debug_printf(L
"CTextRenderer::PrintfAt vswprintf failed (buffer size exceeded?) - return value %d, errno %d\n", ret, errno);
116 Put(0.0f, 0.0f, buf);
119 m_Font->CalculateStringSize(buf, w, h);
148 std::vector<u16> indexes;
149 std::vector<t2f_v2i> vertexes;
151 for (
size_t i = 0; i <
m_Batches.size(); ++i)
155 if (batch.
text.empty())
158 const std::map<u16, UnifontGlyphData>& glyphs = batch.
font->GetGlyphs();
160 m_Shader->BindTexture(str_tex, batch.
font->GetTexture());
166 if (batch.
font->HasRGB())
174 vertexes.resize(batch.
text.size()*4);
177 indexes.resize(batch.
text.size()*6);
180 for (
size_t i = 0; i < batch.
text.size(); ++i)
182 std::map<u16, UnifontGlyphData>::const_iterator it = glyphs.find(batch.
text[i]);
184 if (it == glyphs.end())
185 it = glyphs.find(0xFFFD);
187 if (it == glyphs.end())
192 vertexes[i*4].u = g.
u1;
193 vertexes[i*4].v = g.
v0;
194 vertexes[i*4].x = g.
x1 + x;
195 vertexes[i*4].y = g.
y0;
197 vertexes[i*4+1].u = g.
u0;
198 vertexes[i*4+1].v = g.
v0;
199 vertexes[i*4+1].x = g.
x0 + x;
200 vertexes[i*4+1].y = g.
y0;
202 vertexes[i*4+2].u = g.
u0;
203 vertexes[i*4+2].v = g.
v1;
204 vertexes[i*4+2].x = g.
x0 + x;
205 vertexes[i*4+2].y = g.
y1;
207 vertexes[i*4+3].u = g.
u1;
208 vertexes[i*4+3].v = g.
v1;
209 vertexes[i*4+3].x = g.
x1 + x;
210 vertexes[i*4+3].y = g.
y1;
212 indexes[i*6+0] = i*4+0;
213 indexes[i*6+1] = i*4+1;
214 indexes[i*6+2] = i*4+2;
215 indexes[i*6+3] = i*4+2;
216 indexes[i*6+4] = i*4+3;
217 indexes[i*6+5] = i*4+0;
223 m_Shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT,
sizeof(
t2f_v2i), &vertexes[0].u);
225 glDrawElements(GL_TRIANGLES, indexes.size(), GL_UNSIGNED_SHORT, &indexes[0]);
void Translate(float x, float y, float z)
shared_ptr< CFont > m_Font
void PrintfAt(float x, float y, const wchar_t *fmt,...)
Print formatted text at (x,y) under the current transform.
void Translate(float x, float y, float z)
void SetTranslation(float x, float y, float z)
void Render()
Render all of the previously printed text calls.
void PutAdvance(const wchar_t *buf)
Print text at (0,0) under the current transform, and advance the transform by the width of the text...
CTextRenderer(const CShaderProgramPtr &shader)
CShaderProgramPtr m_Shader
void Put(float x, float y, const wchar_t *buf)
Print text at (x,y) under the current transform, and advance the transform by the width of the text...
void Color(const CColor &color)
Set the color for subsequent print calls.
void PrintfAdvance(const wchar_t *fmt,...)
Print formatted text at (0,0) under the current transform, and advance the transform by the width of ...
void ResetTransform()
Reset the text transform to the default, with (0,0) in the top-left of the screen.
std::vector< SBatch > m_Batches
void Scale(float x_scale, float y_scale, float z_scale)
void SetTransform(const CMatrix3D &transform)
void Font(const CStrW &font)
Set the font for subsequent print calls.
void SetOrtho(float l, float r, float b, float t, float n, float f)
shared_ptr< CShaderProgram > CShaderProgramPtr
std::map< CStrW, shared_ptr< CFont > > m_Fonts
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).