font draw improvements

This commit is contained in:
MihailRis
2022-07-15 16:54:35 +03:00
committed by GitHub
parent 889b2a62b5
commit fa4538c124
3 changed files with 64 additions and 32 deletions
+57 -25
View File
@@ -43,35 +43,67 @@ bool Font::isPrintableChar(int c) {
#define RES 16
void Font::draw(Batch2D* batch, std::wstring text, int x, int y) {
for (unsigned c : text){
if (isPrintableChar(c)){
batch->texture(pages[c >> 8]);
batch->sprite(x, y, RES, RES, 16, c, vec4(1.0f));
int page = 0;
int next = 10000;
int init_x = x;
do {
for (unsigned c : text){
if (isPrintableChar(c)){
int charpage = c >> 8;
if (charpage == page){
Texture* texture = pages[charpage];
if (texture == nullptr){
texture = pages[0];
}
batch->texture(pages[charpage]);
batch->sprite(x, y, RES, RES, 16, c, vec4(1.0f));
}
else if (charpage > page && charpage < next){
next = charpage;
}
}
x += getGlyphWidth(c);
}
x += getGlyphWidth(c);
}
page = next;
next = 10000;
x = init_x;
} while (page < 10000);
}
void Font::drawWithShadow(Batch2D* batch, std::wstring text, int x, int y) {
for (unsigned c : text){
if (isPrintableChar(c)){
Texture* texture = pages[c >> 8];
if (texture == nullptr){
texture = pages[0];
}
batch->texture(texture);
batch->sprite(x+1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x+1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x-1, y, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x+1, y, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
void Font::drawWithOutline(Batch2D* batch, std::wstring text, int x, int y) {
int page = 0;
int next = 10000;
int init_x = x;
do {
for (unsigned c : text){
if (isPrintableChar(c)){
int charpage = c >> 8;
if (charpage == page){
Texture* texture = pages[charpage];
if (texture == nullptr){
texture = pages[0];
}
batch->texture(pages[charpage]);
batch->sprite(x+1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x+1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x-1, y, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x+1, y, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x-1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x+1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x+1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x-1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x-1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x+1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x+1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x-1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
batch->sprite(x, y, RES, RES, 16, c, vec4(1.0f));
batch->sprite(x, y, RES, RES, 16, c, vec4(1.0f));
}
else if (charpage > page && charpage < next){
next = charpage;
}
}
x += getGlyphWidth(c);
}
x += getGlyphWidth(c);
}
page = next;
next = 10000;
x = init_x;
} while (page < 10000);
}