aboutsummaryrefslogtreecommitdiff
path: root/util/sokol_debugtext.h
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2022-11-14 18:14:40 +0100
committerAndre Weissflog <floooh@gmail.com>2022-11-14 18:14:40 +0100
commit7e6e72b9b86850086e4ab8e7427330d4c196fd5f (patch)
tree1c9e379ca2ea4c05a7dd896a18e103a08a7bb882 /util/sokol_debugtext.h
parent9c38988a4b9e11182e2ddf08c4d64553d8c99ace (diff)
sokol_debugtext.h: fix texturing artefacts by spacing out character cells in font texture
Diffstat (limited to 'util/sokol_debugtext.h')
-rw-r--r--util/sokol_debugtext.h28
1 files changed, 12 insertions, 16 deletions
diff --git a/util/sokol_debugtext.h b/util/sokol_debugtext.h
index 574b0af2..3305c0e0 100644
--- a/util/sokol_debugtext.h
+++ b/util/sokol_debugtext.h
@@ -3539,7 +3539,8 @@ typedef struct {
sdtx_context cur_ctx_id;
_sdtx_context_t* cur_ctx; // may be 0!
_sdtx_context_pool_t context_pool;
- uint8_t font_pixels[SDTX_MAX_FONTS * 256 * 8 * 8];
+ // NOTE: each char cell is an 8x8 grid at the top left of a 16x16 grid
+ uint8_t font_pixels[SDTX_MAX_FONTS * 256 * 16 * 16];
} _sdtx_t;
static _sdtx_t _sdtx;
@@ -3870,7 +3871,8 @@ static void _sdtx_unpack_font(const sdtx_font_desc_t* font_desc, uint8_t* out_pi
for (int line = 0; line < 8; line++) {
uint8_t bits = *ptr++;
for (int x = 0; x < 8; x++) {
- out_pixels[line*256*8 + chr*8 + x] = ((bits>>(7-x)) & 1) ? 0xFF : 0x00;
+ // NOTE: each character cell is an 8x8 grid at the top left of a 16x16 grid
+ out_pixels[line*256*16 + chr*16 + x] = ((bits>>(7-x)) & 1) ? 0xFF : 0x00;
}
}
}
@@ -3937,8 +3939,8 @@ static void _sdtx_setup_common(void) {
SOKOL_ASSERT(SG_INVALID_ID != _sdtx.shader.id);
/* unpack font data */
- memset(_sdtx.font_pixels, 0xFF, sizeof(_sdtx.font_pixels));
- const int unpacked_font_size = 256 * 8 * 8;
+ memset(_sdtx.font_pixels, 0, sizeof(_sdtx.font_pixels));
+ const int unpacked_font_size = (int) (sizeof(_sdtx.font_pixels) / SDTX_MAX_FONTS);
for (int i = 0; i < SDTX_MAX_FONTS; i++) {
if (_sdtx.desc.fonts[i].data.ptr) {
_sdtx_unpack_font(&_sdtx.desc.fonts[i], &_sdtx.font_pixels[i * unpacked_font_size]);
@@ -3948,8 +3950,8 @@ static void _sdtx_setup_common(void) {
/* create font texture */
sg_image_desc img_desc;
_sdtx_clear(&img_desc, sizeof(img_desc));
- img_desc.width = 256 * 8;
- img_desc.height = SDTX_MAX_FONTS * 8;
+ img_desc.width = 256 * 16;
+ img_desc.height = SDTX_MAX_FONTS * 16;
img_desc.pixel_format = SG_PIXELFORMAT_R8;
img_desc.min_filter = SG_FILTER_NEAREST;
img_desc.mag_filter = SG_FILTER_NEAREST;
@@ -4081,18 +4083,12 @@ static void _sdtx_render_char(_sdtx_context_t* ctx, uint8_t c) {
const float y1 = y0 + ctx->glyph_size.y;
// glyph width and heigth in font texture space
- const uint16_t uvw = 0x10000 / 0x100;
- const uint16_t uvh = 0x10000 / SDTX_MAX_FONTS;
- const uint16_t u0 = ((uint16_t)c) * uvw;
- const uint16_t v0 = ((uint16_t)ctx->cur_font) * uvh;
+ const uint16_t uvw = 0x10000 / (0x100 * 2);
+ const uint16_t uvh = 0x10000 / (SDTX_MAX_FONTS * 2);
+ const uint16_t u0 = ((uint16_t)c) * uvw * 2;
+ const uint16_t v0 = ((uint16_t)ctx->cur_font) * uvh * 2;
uint16_t u1 = u0 + uvw;
uint16_t v1 = v0 + uvh;
- if (u1 == 0x0000) {
- u1 = 0xFFFF;
- }
- if (v1 == 0x0000) {
- v1 = 0xFFFF;
- }
const uint32_t color = ctx->color;
// write 6 vertices