Correctly align text rendering to baseline
This commit is contained in:
parent
5ef54e16be
commit
13a2152bf6
Binary file not shown.
@ -9,6 +9,12 @@
|
||||
#include "Dengine/Platform.h"
|
||||
#include "Dengine/AssetManager.h"
|
||||
|
||||
//#define WT_RENDER_FONT_FILE
|
||||
#ifdef WT_RENDER_FONT_FILE
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <STB/stb_image_write.h>
|
||||
#endif
|
||||
|
||||
Texture *asset_getTexture(AssetManager *assetManager, const enum TexList type)
|
||||
{
|
||||
if (type < texlist_count)
|
||||
@ -251,6 +257,9 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
|
||||
i32 glyphsRemaining = numGlyphs;
|
||||
i32 glyphsOnCurrRow = glyphsPerRow;
|
||||
|
||||
// TODO(doyle): We copy over the bitmap direct to the font sheet, should we
|
||||
// align the baselines up so we don't need to do baseline adjusting at
|
||||
// render?
|
||||
i32 atlasIndex = 0;
|
||||
for (i32 row = 0; row < MAX_TEXTURE_SIZE; row++)
|
||||
{
|
||||
@ -331,6 +340,12 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
|
||||
CAST(u8 *)fontBitmap);
|
||||
assetManager->textures[texlist_font] = tex;
|
||||
|
||||
#ifdef WT_RENDER_FONT_FILE
|
||||
/* save out a 4 channel image */
|
||||
stbi_write_png("out.png", MAX_TEXTURE_SIZE, MAX_TEXTURE_SIZE, 4, fontBitmap,
|
||||
MAX_TEXTURE_SIZE * 4);
|
||||
#endif
|
||||
|
||||
font->tex = &assetManager->textures[texlist_font];
|
||||
font->atlas = &assetManager->texAtlas[texlist_font];
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "Dengine/OpenGL.h"
|
||||
#include "Dengine/Renderer.h"
|
||||
|
||||
#define RENDER_BOUNDING_BOX FALSE
|
||||
|
||||
void renderer_entity(Renderer *renderer, Entity *entity, f32 rotate, v3 color)
|
||||
{
|
||||
renderer_object(renderer, entity->pos, entity->size, rotate, color,
|
||||
@ -28,7 +30,7 @@ void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v3 color,
|
||||
// TODO(doyle): Unimplemented
|
||||
// this->shader->uniformSetVec3f("spriteColor", color);
|
||||
|
||||
#if 1
|
||||
#if RENDER_BOUNDING_BOX
|
||||
glBindVertexArray(renderer->vao);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, renderer->numVertexesInVbo);
|
||||
glBindVertexArray(0);
|
||||
|
@ -318,7 +318,6 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
|
||||
RenderQuad worldQuads[ARRAY_COUNT(world->tiles)] = {0};
|
||||
i32 quadIndex = 0;
|
||||
|
||||
|
||||
/* Render background tiles */
|
||||
const v2 tileSize = V2(CAST(f32) state->tileSize, CAST(f32) state->tileSize);
|
||||
for (i32 i = 0; i < ARRAY_COUNT(world->tiles); i++)
|
||||
@ -358,16 +357,7 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
|
||||
i32 codepoint = string[i];
|
||||
i32 relativeIndex = codepoint - font->codepointRange.x;
|
||||
CharMetrics charMetric = font->charMetrics[relativeIndex];
|
||||
|
||||
i32 charBaseline = (font->maxSize.h - charMetric.trueSize.h);
|
||||
if (codepoint == 'a')
|
||||
{
|
||||
yPosOnScreen = baseline - charBaseline;
|
||||
}
|
||||
else
|
||||
{
|
||||
yPosOnScreen = baseline;
|
||||
}
|
||||
yPosOnScreen = baseline - charMetric.offset.y;
|
||||
|
||||
const v4 charRectOnScreen = getRect(
|
||||
V2(xPosOnScreen, yPosOnScreen),
|
||||
|
@ -32,6 +32,7 @@ typedef struct TexAtlas
|
||||
v4 texRect[128];
|
||||
} TexAtlas;
|
||||
|
||||
// TODO(doyle): We only use the offset and advance metric at the moment, remove?
|
||||
typedef struct FontMetrics
|
||||
{
|
||||
i32 ascent;
|
||||
@ -43,6 +44,7 @@ typedef struct CharMetrics
|
||||
{
|
||||
i32 advance;
|
||||
i32 leftSideBearing;
|
||||
// TODO(doyle): Utilise kerning
|
||||
i32 *kerning;
|
||||
v2i offset;
|
||||
v2i trueSize;
|
||||
|
Loading…
Reference in New Issue
Block a user