mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
Audio module, simple text rendering
This commit is contained in:
parent
e96fd909ea
commit
1770acbfef
15 changed files with 702 additions and 17 deletions
40
src/graphics/Font.cpp
Normal file
40
src/graphics/Font.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "Font.h"
|
||||
#include "Texture.h"
|
||||
#include "Batch2D.h"
|
||||
|
||||
Font::Font(Texture* texture) : texture(texture) {
|
||||
}
|
||||
|
||||
Font::~Font(){
|
||||
delete texture;
|
||||
}
|
||||
|
||||
|
||||
void Font::draw(Batch2D* batch, std::string text, int x, int y) {
|
||||
for (char c : text){
|
||||
float u = (c % 16) / 16.0f;
|
||||
float v = 1.0f - ((c / 16) / 16.0f) - 1.0f/16.0f;
|
||||
batch->rect(x, y, 8, 8, u, v, 1.0f/16.0f, 1.0f/16.0f, 1,1,1,1);
|
||||
|
||||
int gw = 7;
|
||||
switch (c){
|
||||
case 'l':
|
||||
case 'i':
|
||||
case 'j':
|
||||
case '|':
|
||||
case '.':
|
||||
case ',':
|
||||
case ':':
|
||||
case ';':
|
||||
gw = 3;
|
||||
break;
|
||||
case 't':
|
||||
gw = 5;
|
||||
break;
|
||||
case ' ':
|
||||
gw = 3;
|
||||
break;
|
||||
}
|
||||
x += gw;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue