aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2025-10-14 16:20:23 -0400
committerJack Jamison <jackqjamison@gmail.com>2025-10-14 16:20:23 -0400
commit92b0fd4608e11d505c4aabee9449ad564aaae69d (patch)
tree8fe59efeee5cc1179622ce88d3e739ef0573edaa
parent5fa96e59fa378af36e90cdd8ee741d164304e3b8 (diff)
bearing works
-rw-r--r--font.c4
-rw-r--r--graphics.c16
-rw-r--r--state.h4
3 files changed, 13 insertions, 11 deletions
diff --git a/font.c b/font.c
index 533788c..85e0a24 100644
--- a/font.c
+++ b/font.c
@@ -111,7 +111,7 @@ void atlas_create_texture(client_state* state) {
}
metric_t* metric = &state->atlas.metrics[i];
- metric->texture_offset = (float)x / state->atlas.width;
+ metric->texture_x_start = (float)x / state->atlas.width;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D(
@@ -125,7 +125,7 @@ void atlas_create_texture(client_state* state) {
GL_UNSIGNED_BYTE,
state->ft_face->glyph->bitmap.buffer);
x += state->ft_face->glyph->bitmap.width;
- metric->texture_size = (float)x / state->atlas.width;
+ metric->texture_x_end = (float)x / state->atlas.width;
}
}
diff --git a/graphics.c b/graphics.c
index 99cb457..7846f6c 100644
--- a/graphics.c
+++ b/graphics.c
@@ -95,14 +95,16 @@ void render_frame(client_state *state) {
for ( int n = 0; n < array_size(state->input_buffer); n++ )
{
char c = state->input_buffer[n];
- metric_t* metric = &state->atlas.metrics[(int)c];
-
- glTexCoord2f(metric->texture_offset, 0.0f); glVertex2f(pen_x, pen_y);
- glTexCoord2f(metric->texture_offset, 1.0f); glVertex2f(pen_x, pen_y + metric->bitmap_height);
- glTexCoord2f(metric->texture_size, 1.0f); glVertex2f(pen_x + metric->bitmap_width, pen_y + metric->bitmap_height);
- glTexCoord2f(metric->texture_size, 0.0f); glVertex2f(pen_x + metric->bitmap_width, pen_y);
+ metric_t* m = &state->atlas.metrics[(int)c];
+
+ float start_x = pen_x + m->bearing_x;
+ float start_y = pen_y - m->bearing_y;
+ glTexCoord2f(m->texture_x_start, 0.0f); glVertex2f(start_x, start_y);
+ glTexCoord2f(m->texture_x_start, 1.0f); glVertex2f(start_x, start_y + m->bitmap_height);
+ glTexCoord2f(m->texture_x_end, 1.0f); glVertex2f(start_x + m->bitmap_width, start_y + m->bitmap_height);
+ glTexCoord2f(m->texture_x_end, 0.0f); glVertex2f(start_x + m->bitmap_width, start_y);
- pen_x += metric->advance_x;
+ pen_x += m->advance_x;
}
glEnd();
diff --git a/state.h b/state.h
index 4e4b99a..d75bac2 100644
--- a/state.h
+++ b/state.h
@@ -22,8 +22,8 @@ typedef struct {
float advance_x, advance_y;
uint32_t bitmap_width, bitmap_height;
int32_t bearing_x, bearing_y;
- float texture_offset;
- float texture_size;
+ float texture_x_start;
+ float texture_x_end;
} metric_t;
typedef struct {