|
@@ -1,34 +1,34 @@
|
|
|
#include "client/rendering/FontRenderer.h"
|
|
|
|
|
|
-const size_t FontRenderer::BUFFER_LENGTH = 8 * 1024 * 1024;
|
|
|
+const u64 FontRenderer::BUFFER_LENGTH = 8 * 1024 * 1024;
|
|
|
|
|
|
-FontRenderer::FontRenderer() : tex("resources/font8x8.png"), offset(BUFFER_LENGTH), vba(0), vbo(0) {
|
|
|
- glGenVertexArrays(1, &vba);
|
|
|
- glBindVertexArray(vba);
|
|
|
-
|
|
|
- glGenBuffers(1, &vbo);
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
|
+static void setVertexAttribute(uint index, uint length, uint offset) {
|
|
|
+ glVertexAttribPointer(index, length, GL_FLOAT, false, sizeof (float) * 7, static_cast<float*> (0) + offset);
|
|
|
+ glEnableVertexAttribArray(index);
|
|
|
+}
|
|
|
|
|
|
- glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof (float) * 7, static_cast<float*> (0));
|
|
|
- glEnableVertexAttribArray(0);
|
|
|
+FontRenderer::FontRenderer() : tex("resources/font8x8.png"), offset(BUFFER_LENGTH), vertexArray(0), vertexBuffer(0) {
|
|
|
+ glGenVertexArrays(1, &vertexArray);
|
|
|
+ glBindVertexArray(vertexArray);
|
|
|
|
|
|
- glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof (float) * 7, static_cast<float*> (0) + 2);
|
|
|
- glEnableVertexAttribArray(1);
|
|
|
+ glGenBuffers(1, &vertexBuffer);
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
|
|
|
|
|
- glVertexAttribPointer(2, 3, GL_FLOAT, false, sizeof (float) * 7, static_cast<float*> (0) + 4);
|
|
|
- glEnableVertexAttribArray(2);
|
|
|
+ setVertexAttribute(0, 2, 0);
|
|
|
+ setVertexAttribute(1, 2, 2);
|
|
|
+ setVertexAttribute(2, 3, 4);
|
|
|
}
|
|
|
|
|
|
FontRenderer::~FontRenderer() {
|
|
|
- glDeleteVertexArrays(1, &vba);
|
|
|
- glDeleteBuffers(1, &vbo);
|
|
|
+ glDeleteBuffers(1, &vertexBuffer);
|
|
|
+ glDeleteVertexArrays(1, &vertexArray);
|
|
|
}
|
|
|
|
|
|
void FontRenderer::drawString(float x, float y, const char* text) {
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
|
|
|
|
|
- const size_t maxIndex = 256;
|
|
|
- const size_t maxLength = maxIndex * 4 * sizeof (float) * 7;
|
|
|
+ const u64 maxIndex = 256;
|
|
|
+ const u64 maxLength = maxIndex * 4 * sizeof (float) * 7;
|
|
|
|
|
|
if(offset + maxLength >= BUFFER_LENGTH) {
|
|
|
offset = 0;
|
|
@@ -40,8 +40,8 @@ void FontRenderer::drawString(float x, float y, const char* text) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- size_t index = 0;
|
|
|
- size_t i = 0;
|
|
|
+ u64 index = 0;
|
|
|
+ u64 i = 0;
|
|
|
float r = 1.0f;
|
|
|
float g = 1.0f;
|
|
|
float b = 1.0f;
|
|
@@ -59,9 +59,9 @@ void FontRenderer::drawString(float x, float y, const char* text) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- float minX = (c & 0xF) * (1.0f / 16.0f);
|
|
|
+ float minX = (c & 0xF) * (1.0f / 16.0f) + 1.0f / 128.0f;
|
|
|
float minY = (c >> 4) * (1.0f / 16.0f);
|
|
|
- float maxX = minX + (1.0f / 16.0f);
|
|
|
+ float maxX = minX + (1.0f / 16.0f) - 2.0f / 128.0f;
|
|
|
float maxY = minY + (1.0f / 16.0f);
|
|
|
|
|
|
buffer[i++] = x;
|
|
@@ -80,7 +80,7 @@ void FontRenderer::drawString(float x, float y, const char* text) {
|
|
|
buffer[i++] = g;
|
|
|
buffer[i++] = b;
|
|
|
|
|
|
- buffer[i++] = x + 8;
|
|
|
+ buffer[i++] = x + 6;
|
|
|
buffer[i++] = y;
|
|
|
buffer[i++] = maxX;
|
|
|
buffer[i++] = minY;
|
|
@@ -88,7 +88,7 @@ void FontRenderer::drawString(float x, float y, const char* text) {
|
|
|
buffer[i++] = g;
|
|
|
buffer[i++] = b;
|
|
|
|
|
|
- buffer[i++] = x + 8;
|
|
|
+ buffer[i++] = x + 6;
|
|
|
buffer[i++] = y + 8;
|
|
|
buffer[i++] = maxX;
|
|
|
buffer[i++] = maxY;
|
|
@@ -96,12 +96,12 @@ void FontRenderer::drawString(float x, float y, const char* text) {
|
|
|
buffer[i++] = g;
|
|
|
buffer[i++] = b;
|
|
|
|
|
|
- x += 8;
|
|
|
+ x += 6;
|
|
|
index++;
|
|
|
}
|
|
|
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
|
- glBindVertexArray(vba);
|
|
|
+ glBindVertexArray(vertexArray);
|
|
|
tex.bind(0);
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, offset / (sizeof (float) * 7), i / 7);
|
|
|
offset += maxLength;
|