diff --git a/src/parts/render.c b/src/parts/render.c index 8da2aa2..62a9379 100644 --- a/src/parts/render.c +++ b/src/parts/render.c @@ -45,15 +45,26 @@ static struct { GLint multiply_color; } parts_shader; -static void parts_render_text(struct parts *parts, struct parts_common *common) +static void parts_render_text(struct parts *parts, struct parts_text *t) { - Rectangle rect = { - .x = parts->global.pos.x + common->origin_offset.x, - .y = parts->global.pos.y + common->origin_offset.y, - .w = common->w, - .h = common->h - }; - gfx_render_texture(&parts->states[parts->state].common.texture, &rect); + int x = parts->global.pos.x + t->common.origin_offset.x; + int y = parts->global.pos.y + t->common.origin_offset.y; + for (int i = 0; i < t->nr_lines; i++) { + struct parts_text_line *line = &t->lines[i]; + for (int j = 0; j < line->nr_chars; j++) { + struct parts_text_char *ch = &line->chars[j]; + Rectangle rect = { + .x = x, + .y = y, + .w = ch->t.w, + .h = ch->t.h + }; + gfx_render_texture(&ch->t, &rect); + x += ch->advance; + } + x = parts->global.pos.x + t->common.origin_offset.x; + y += line->height; + } } static void parts_render_texture(struct texture *texture, mat4 mw_transform, Rectangle *rect, float blend_rate, vec3 add_color, vec3 multiply_color) @@ -248,8 +259,7 @@ void parts_render(struct parts *parts) parts_render_cg(parts, &state->common); break; case PARTS_TEXT: - if (state->common.texture.handle) - parts_render_text(parts, &state->common); + parts_render_text(parts, &state->text); break; case PARTS_FLASH: parts_render_flash(parts, &state->flash); diff --git a/src/parts/text.c b/src/parts/text.c index ee4cb0a..b72c8b4 100644 --- a/src/parts/text.c +++ b/src/parts/text.c @@ -104,7 +104,7 @@ void parts_text_append(struct parts *parts, struct parts_text *t, struct string msgp = parts_text_append_char(t, msgp); } - // calculate required dimensions of texture + // calculate dimensions of the text float f_width = 0; int height = 0; for (int i = 0; i < t->nr_lines; i++) { @@ -115,26 +115,6 @@ void parts_text_append(struct parts *parts, struct parts_text *t, struct string if (!width || !height) return; - // initialize texture - if (t->common.texture.handle) - gfx_delete_texture(&t->common.texture); - gfx_init_texture_rgba(&t->common.texture, width, height, (SDL_Color){0,0,0,0}); - - // copy glyph textures to main texture - t->cursor.x = 0; - t->cursor.y = 0; - for (int i = 0; i < t->nr_lines; i++) { - struct parts_text_line *line = &t->lines[i]; - for (int i = 0; i < line->nr_chars; i++) { - struct parts_text_char *ch = &line->chars[i]; - gfx_copy_with_alpha_map(&t->common.texture, - lroundf(t->cursor.x), t->cursor.y, - &ch->t, 0, 0, ch->t.w, ch->t.h); - t->cursor.x += ch->advance; - } - t->cursor.x = 0; - t->cursor.y += line->height; - } parts_set_dims(parts, &t->common, width, height); }