VOXELFONT: option to mirror y axis

master
Martin Gerhardy 2018-11-16 22:01:34 +01:00
parent 49b620a2ad
commit bc7cefea4e
5 changed files with 14 additions and 2 deletions

View File

@ -128,6 +128,7 @@ bool VoxelFont::renderGlyphs(const char* string) {
int spaceWidth = 0;
int chars = 0;
const bool mergeQuads = _optionMask & MergeQuads;
const bool originUpperLeft = _optionMask & OriginUpperLeft;
for (int c = core::utf8::next(s); c != -1; c = core::utf8::next(s)) {
int w;
int h;
@ -156,8 +157,14 @@ bool VoxelFont::renderGlyphs(const char* string) {
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
if (bitmap[y * w + x] >= 25) {
int finalY;
if (originUpperLeft) {
finalY = y;
} else {
finalY = regionH - y;
}
for (int i = 0; i < _thickness; ++i) {
v.setVoxel(glm::ivec3(x + ix0, regionH - y, i), voxel);
v.setVoxel(glm::ivec3(x + ix0, finalY, i), voxel);
}
}
}

View File

@ -47,6 +47,7 @@ public:
~VoxelFont();
static const uint8_t MergeQuads = 1 << 0;
static const uint8_t OriginUpperLeft = 1 << 1;
bool init(const char* font, int fontSize, int thickness, uint8_t optionMask, const char* glyphs);
void shutdown();

View File

@ -41,7 +41,7 @@ private:
const int _depth;
const uint8_t _optionMask;
public:
VoxelFontRenderer(int fontSize, int depth = 4, uint8_t optionMask = voxel::VoxelFont::MergeQuads);
VoxelFontRenderer(int fontSize, int depth = 4, uint8_t optionMask = voxel::VoxelFont::OriginUpperLeft | voxel::VoxelFont::MergeQuads);
bool init() override;
void shutdown() override;

View File

@ -131,6 +131,9 @@ void TestVoxelFont::onRenderUI() {
if (ImGui::Checkbox("Merge Quads", &_mergeQuads)) {
changeFontSize(0);
}
if (ImGui::Checkbox("Upper left (origin)", &_upperLeft)) {
changeFontSize(0);
}
ImGui::Text("Font vertices: %i, indices: %i", _vertices, _indices);
ImGui::Text("Ctrl/+ Ctrl/-: Change font thickness");
ImGui::Text("Space: Toggle merge quads");

View File

@ -20,6 +20,7 @@ private:
int _fontSize = 20;
int _thickness = 4;
bool _mergeQuads = false;
bool _upperLeft = false;
int _vertices = 0;
int _indices = 0;