|
@@ -1,31 +1,31 @@
|
|
#include "client/rendering/FontRenderer.h"
|
|
#include "client/rendering/FontRenderer.h"
|
|
#include "gaming-core/wrapper/Attributes.h"
|
|
#include "gaming-core/wrapper/Attributes.h"
|
|
-#include "gaming-core/utils/List.h"
|
|
+#include "gaming-core/utils/Buffer.h"
|
|
|
|
|
|
FontRenderer::FontRenderer() : tex("resources/font8x8.png") {
|
|
FontRenderer::FontRenderer() : tex("resources/font8x8.png") {
|
|
- vertexBuffer.setAttributes(Attributes().addFloat(2).addFloat(2).addFloat(3));
|
|
+ vertexBuffer.setAttributes(Attributes().addFloat(2).addFloat(2).addColor4());
|
|
- vertexBuffer.setStreamData(256 * 4 * 7 * sizeof(float));
|
|
+ vertexBuffer.setStreamData(MAX_CHARS * VERTEX_SIZE * 4);
|
|
}
|
|
}
|
|
|
|
|
|
void FontRenderer::drawString(float x, float y, const char* text) {
|
|
void FontRenderer::drawString(float x, float y, const char* text) {
|
|
- const int maxIndex = 256;
|
|
+ Buffer<MAX_CHARS * VERTEX_SIZE * 4> buffer;
|
|
-
|
|
|
|
- List<float, maxIndex * 4 * 7> buffer;
|
|
|
|
|
|
|
|
int index = 0;
|
|
int index = 0;
|
|
- float r = 1.0f;
|
|
+ Color4 color(0xFF, 0xFF, 0xFF, 0xFF);
|
|
- float g = 1.0f;
|
|
|
|
- float b = 1.0f;
|
|
|
|
|
|
|
|
- while(text[index] != '\0' && index < maxIndex) {
|
|
+ while(text[index] != '\0' && index < MAX_CHARS) {
|
|
- char c = text[index];
|
|
+ char32_t c = text[index];
|
|
|
|
+ if(c > 128 && index + 1 < MAX_CHARS && text[index + 1] != '\0') {
|
|
|
|
+ index++;
|
|
|
|
+ c = (text[index] & 0x3F) | ((c & 0x1F) << 6);
|
|
|
|
+ }
|
|
if(c == '&') {
|
|
if(c == '&') {
|
|
if(text[index + 1] == '\0' || text[index + 2] == '\0' || text[index + 3] == '\0') {
|
|
if(text[index + 1] == '\0' || text[index + 2] == '\0' || text[index + 3] == '\0') {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- r = (text[index + 1] - '0') * (1.0f / 9.0f);
|
|
+ color[0] = ((text[index + 1] - '0') * 255) / 9;
|
|
- g = (text[index + 2] - '0') * (1.0f / 9.0f);
|
|
+ color[1] = ((text[index + 2] - '0') * 255) / 9;
|
|
- b = (text[index + 3] - '0') * (1.0f / 9.0f);
|
|
+ color[2] = ((text[index + 3] - '0') * 255) / 9;
|
|
index += 4;
|
|
index += 4;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -35,40 +35,16 @@ void FontRenderer::drawString(float x, float y, const char* text) {
|
|
float maxX = minX + (1.0f / 16.0f) - 2.0f / 128.0f;
|
|
float maxX = minX + (1.0f / 16.0f) - 2.0f / 128.0f;
|
|
float maxY = minY + (1.0f / 16.0f);
|
|
float maxY = minY + (1.0f / 16.0f);
|
|
|
|
|
|
- buffer.add(x);
|
|
+ buffer.add(x).add(y).add(minX).add(minY).add(color);
|
|
- buffer.add(y);
|
|
+ buffer.add(x).add(y + 8).add(minX).add(maxY).add(color);
|
|
- buffer.add(minX);
|
|
+ buffer.add(x + 6).add(y).add(maxX).add(minY).add(color);
|
|
- buffer.add(minY);
|
|
+ buffer.add(x + 6).add(y + 8).add(maxX).add(maxY).add(color);
|
|
- buffer.add(r);
|
|
|
|
- buffer.add(g);
|
|
|
|
- buffer.add(b);
|
|
|
|
- buffer.add(x);
|
|
|
|
- buffer.add(y + 8);
|
|
|
|
- buffer.add(minX);
|
|
|
|
- buffer.add(maxY);
|
|
|
|
- buffer.add(r);
|
|
|
|
- buffer.add(g);
|
|
|
|
- buffer.add(b);
|
|
|
|
- buffer.add(x + 6);
|
|
|
|
- buffer.add(y);
|
|
|
|
- buffer.add(maxX);
|
|
|
|
- buffer.add(minY);
|
|
|
|
- buffer.add(r);
|
|
|
|
- buffer.add(g);
|
|
|
|
- buffer.add(b);
|
|
|
|
- buffer.add(x + 6);
|
|
|
|
- buffer.add(y + 8);
|
|
|
|
- buffer.add(maxX);
|
|
|
|
- buffer.add(maxY);
|
|
|
|
- buffer.add(r);
|
|
|
|
- buffer.add(g);
|
|
|
|
- buffer.add(b);
|
|
|
|
|
|
|
|
x += 6;
|
|
x += 6;
|
|
index++;
|
|
index++;
|
|
}
|
|
}
|
|
|
|
|
|
tex.bindTo(0);
|
|
tex.bindTo(0);
|
|
- vertexBuffer.updateData(0, buffer.getLength() * sizeof(float), buffer.begin());
|
|
+ vertexBuffer.updateData(0, buffer.getLength(), buffer);
|
|
- vertexBuffer.drawStrip(buffer.getLength() / 7);
|
|
+ vertexBuffer.drawStrip(buffer.getLength() / VERTEX_SIZE);
|
|
}
|
|
}
|