Added text shadow, block indicator outline
This commit is contained in:
parent
88c1695903
commit
81d246f3d0
@ -71,6 +71,13 @@ void Batch2D::rect(float x, float y, float w, float h){
|
||||
vertex(x+w, y+h, 1, 1, r,g,b,a);
|
||||
}
|
||||
|
||||
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index, vec4 tint){
|
||||
float scale = 1.0f / (float)atlasRes;
|
||||
float u = (index % atlasRes) * scale;
|
||||
float v = 1.0f - ((index / atlasRes) * scale) - scale;
|
||||
rect(x, y, w, h, u, v, scale, scale, tint.r, tint.g, tint.b, tint.a);
|
||||
}
|
||||
|
||||
void Batch2D::rect(float x, float y, float w, float h,
|
||||
float u, float v, float tx, float ty,
|
||||
float r, float g, float b, float a){
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
using namespace glm;
|
||||
|
||||
class Mesh;
|
||||
class Texture;
|
||||
|
||||
@ -27,6 +29,7 @@ public:
|
||||
|
||||
void begin();
|
||||
void texture(Texture* texture);
|
||||
void sprite(float x, float y, float w, float h, int atlasRes, int index, vec4 tint);
|
||||
void rect(float x, float y, float w, float h);
|
||||
void rect(float x, float y, float w, float h,
|
||||
float u, float v, float tx, float ty,
|
||||
|
||||
@ -26,11 +26,34 @@ int Font::getGlyphWidth(char c) {
|
||||
}
|
||||
|
||||
|
||||
bool Font::isPrintableChar(char c) {
|
||||
switch (c){
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\f':
|
||||
case '\r':
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
if (isPrintableChar(c))
|
||||
batch->sprite(x, y, 8, 8, 16, c, vec4(1.0f));
|
||||
x += getGlyphWidth(c);
|
||||
}
|
||||
}
|
||||
|
||||
void Font::drawWithShadow(Batch2D* batch, std::string text, int x, int y) {
|
||||
for (char c : text){
|
||||
if (isPrintableChar(c)){
|
||||
batch->sprite(x+1, y+1, 8, 8, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
batch->sprite(x, y, 8, 8, 16, c, vec4(1.0f));
|
||||
}
|
||||
x += getGlyphWidth(c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,9 @@ public:
|
||||
~Font();
|
||||
|
||||
int getGlyphWidth(char c);
|
||||
bool isPrintableChar(char c);
|
||||
void draw(Batch2D* batch, std::string text, int x, int y);
|
||||
void drawWithShadow(Batch2D* batch, std::string text, int x, int y);
|
||||
};
|
||||
|
||||
#endif /* GRAPHICS_FONT_H_ */
|
||||
|
||||
@ -122,21 +122,20 @@ void draw_hud(Player* player, Assets* assets, bool devdata, int fps){
|
||||
batch->begin();
|
||||
batch->texture(font->texture);
|
||||
if (devdata){
|
||||
font->draw(batch, "devdata does not exist", 16, 16);
|
||||
font->draw(batch, std::to_string((int)player->camera->position.x), 10, 30);
|
||||
font->draw(batch, std::to_string((int)player->camera->position.y), 50, 30);
|
||||
font->draw(batch, std::to_string((int)player->camera->position.z), 90, 30);
|
||||
font->draw(batch, "fps:", 16, 42);
|
||||
font->draw(batch, std::to_string(fps), 40, 42);
|
||||
font->drawWithShadow(batch, "devdata does not exist", 16, 16);
|
||||
font->drawWithShadow(batch, std::to_string((int)player->camera->position.x), 10, 30);
|
||||
font->drawWithShadow(batch, std::to_string((int)player->camera->position.y), 50, 30);
|
||||
font->drawWithShadow(batch, std::to_string((int)player->camera->position.z), 90, 30);
|
||||
font->drawWithShadow(batch, "fps:", 16, 42);
|
||||
font->drawWithShadow(batch, std::to_string(fps), 40, 42);
|
||||
}
|
||||
batch->render();
|
||||
|
||||
// choosen block preview
|
||||
Texture* blocks = assets->getTexture("block_select");
|
||||
batch->texture(blocks);
|
||||
float u = (player->choosenBlock % 16) / 16.0f;
|
||||
float v = 1.0f - ((player->choosenBlock / 16) / 16.0f) - 1.0f/16.0f;
|
||||
batch->rect(16, 280, 64, 64, u, v, 1.0f/16.0f, 1.0f/16.0f, 1,1,1,1);
|
||||
batch->sprite(14, 278, 68, 68, 16, player->choosenBlock, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
batch->sprite(16, 280, 64, 64, 16, player->choosenBlock, vec4(1.0f));
|
||||
batch->render();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user