6#include <brenta/text.hpp>
7#include <brenta/font.hpp>
8#include <brenta/renderer/opengl/shader.hpp>
11#include <glm/gtc/matrix_transform.hpp>
12#include <glm/gtc/type_ptr.hpp>
14using namespace brenta;
16void Text::render(
int width,
int height)
const
18 this->font->shader->use();
19 this->font->shader->set_float3(
"textColor",
20 255.99f * this->color.r,
21 255.99f * this->color.g,
22 255.99f * this->color.b);
24 glm::mat4 projection =
25 glm::ortho(0.0f,
static_cast<float>(width), 0.0f,
26 static_cast<float>(height));
28 this->font->shader->set_mat4(
"projection", projection);
30 glActiveTexture(GL_TEXTURE0);
31 this->font->vao.bind();
36 std::string::const_iterator c;
37 for (c = this->text.begin(); c != this->text.end(); c++)
41 float xpos = _x + ch.bearing.x * this->scale;
42 float ypos = _y - (ch.size.y - ch.bearing.y) * this->scale;
44 float w = ch.size.x * this->scale;
45 float h = ch.size.y * this->scale;
49 float vertices[6][4] = {
50 {xpos, ypos + h, 0.0, 0.0}, {xpos, ypos, 0.0, 1.0},
51 {xpos + w, ypos, 1.0, 1.0},
53 {xpos, ypos + h, 0.0, 0.0}, {xpos + w, ypos, 1.0, 1.0},
54 {xpos + w, ypos + h, 1.0, 0.0}};
57 glBindTexture(GL_TEXTURE_2D, ch.texture_id);
60 glBindBuffer(GL_ARRAY_BUFFER, this->font->vbo.get_id());
61 glBufferSubData(GL_ARRAY_BUFFER, 0,
sizeof(vertices), vertices);
63 glBindBuffer(GL_ARRAY_BUFFER, 0);
65 glDrawArrays(GL_TRIANGLES, 0, 6);
68 _x += (ch.advance >> 6)
72 glBindTexture(GL_TEXTURE_2D, 0);