I'm trying to make text writing function. Here:
struct character
{
float advancex, advancey, bitmapw, bitmaph, bitmapl, bitmapt, texx;
};
character* c;
struct point {
GLfloat x;
GLfloat y;
GLfloat z;
GLfloat s;
GLfloat t;
};
point coords[255*6];
void renderText(const char*text,float x,float y,float sizex,float sizey)
{
// ScreenWidth = 640;
// ScreenHeight = 480;
auto l = -ScreenWidth / 2 + x;
auto t = ScreenHeight / 2 + y;
int n = 0;
for (const char *p = text; *p; p++)
{
if (!w || !h)continue;
auto r = l + c[*p].bitmapw*sizex;
auto b = t - c[*p].bitmaph*sizey;
coords[n++] = { l, t, 0, c[*p].texx, c[*p].bitmaph / atlas_height };
coords[n++] = { r, b, 0, c[*p].texx + c[*p].bitmapw / atlas_width, 0 };
coords[n++] = { l, b, 0, c[*p].texx, 0 };
coords[n++] = { l, t, 0, c[*p].texx, c[*p].bitmaph / atlas_height };
coords[n++] = { r, t, 0, c[*p].texx + c[*p].bitmapw / atlas_width, c[*p].bitmaph / atlas_height };
coords[n++] = { r, b, 0, c[*p].texx + c[*p].bitmapw / atlas_width, 0 };
l += c[*p].advancex*sizex;
t += c[*p].advancey*sizey;
}
glBindTexture(GL_TEXTURE_2D, texture2D_ID0);
glBindVertexArray(vertex_array_ID);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_ID);
glBufferSubData(GL_ARRAY_BUFFER,0,n*sizeof(point),coords);
glDrawArrays(GL_TRIANGLES, 0, n);
}
How can I get aligned text? I use orthographic projection given as glm::ortho(-320.0f, +320.0f, 240.0f, -240.0f, 0.1f, 100.f);
and I get this result: