diff --git a/bin32/liboverlay.so b/bin32/liboverlay.so index 7ef261e..39605c8 100755 Binary files a/bin32/liboverlay.so and b/bin32/liboverlay.so differ diff --git a/bin64/liboverlay.so b/bin64/liboverlay.so index fe025c8..19dce4d 100755 Binary files a/bin64/liboverlay.so and b/bin64/liboverlay.so differ diff --git a/include/fontapi_internal.h b/include/fontapi_internal.h index 4bdffb3..c998b84 100644 --- a/include/fontapi_internal.h +++ b/include/fontapi_internal.h @@ -14,14 +14,9 @@ struct fontapi_font_t { int init; - int loaded; - int error; texture_font_t *font; texture_atlas_t *atlas; - - char path[256]; - float size; }; texture_font_t* diff --git a/include/log.h b/include/log.h index 8a640e3..7bc2ba5 100644 --- a/include/log.h +++ b/include/log.h @@ -7,5 +7,15 @@ #pragma once +#define DEBUG 0 + +#if DEBUG + void log_write(const char *format, ...); + +#else + +#define log_write(...) + +#endif diff --git a/src/drawglx.c b/src/drawglx.c index b51c44c..88e6e5e 100644 --- a/src/drawglx.c +++ b/src/drawglx.c @@ -381,7 +381,14 @@ draw_string_internal(float x, float y, const char *string, texture_font_t *fnt, texture_font_load_glyphs(fnt, string); - for (size_t i = 0; i < strlen(string); ++i) + int len = strlen(string); + if (len == 0) + return; + + GLuint indices[6 * len]; + struct vertex_v2ft2fc4f vertices[4 * len]; + + for (size_t i = 0; i < len; ++i) { texture_glyph_t *glyph = texture_font_find_glyph(fnt, &string[i]); if (glyph == NULL) @@ -402,23 +409,27 @@ draw_string_internal(float x, float y, const char *string, texture_font_t *fnt, float s1 = glyph->s1; float t1 = glyph->t1; - GLuint idx = dstream.next_index; - GLuint indices[] = { idx, idx + 1, idx + 2, - idx + 2, idx + 3, idx }; - struct vertex_v2ft2fc4f vertices[] = { - { (vec2){ x0, y0 }, (vec2){ s0, t0 }, color }, - { (vec2){ x0, y1 }, (vec2){ s0, t1 }, color }, - { (vec2){ x1, y1 }, (vec2){ s1, t1 }, color }, - { (vec2){ x1, y0 }, (vec2){ s1, t0 }, color } - }; + GLuint idx = dstream.next_index + i * 4; + indices[i * 6 + 0] = idx; + indices[i * 6 + 1] = idx + 1; + indices[i * 6 + 2] = idx + 2; + indices[i * 6 + 3] = idx + 2; + indices[i * 6 + 4] = idx + 3; + indices[i * 6 + 5] = idx; - dis_push_indices(6, indices); - dis_push_vertices(4, sizeof(struct vertex_v2ft2fc4f), vertices); + vertices[i * 4 + 0] = (struct vertex_v2ft2fc4f){ (vec2){ x0, y0 }, (vec2){ s0, t0 }, color }; + vertices[i * 4 + 1] = (struct vertex_v2ft2fc4f){ (vec2){ x0, y1 }, (vec2){ s0, t1 }, color }; + vertices[i * 4 + 2] = (struct vertex_v2ft2fc4f){ (vec2){ x1, y1 }, (vec2){ s1, t1 }, color }; + vertices[i * 4 + 3] = (struct vertex_v2ft2fc4f){ (vec2){ x1, y0 }, (vec2){ s1, t0 }, color }; pen_x += glyph->advance_x; if (glyph->height > size_y) size_y = glyph->height; } + + dis_push_indices(6 * len, indices); + dis_push_vertices(4 * len, sizeof(struct vertex_v2ft2fc4f), vertices); + if (out_x) *out_x = pen_x - x; if (out_y) @@ -437,6 +448,7 @@ xoverlay_draw_string(float x, float y, const char *string, xoverlay_font_handle_ if (fnt == NULL) { log_write("xoverlay_draw_string: INVALID FONT HANDLE %u\n", font); + return; } fnt->rendermode = RENDER_NORMAL; @@ -459,7 +471,10 @@ xoverlay_draw_string_with_outline(float x, float y, const char *string, xoverlay texture_font_t *fnt = fontapi_get(font); if (fnt == NULL) + { + log_write("xoverlay_draw_string: INVALID FONT HANDLE %u\n", font); return; + } fnt->rendermode = RENDER_OUTLINE_POSITIVE; fnt->outline_thickness = outline_width; diff --git a/src/drawglx.o b/src/drawglx.o index f2ed89a..2cd6fcb 100644 Binary files a/src/drawglx.o and b/src/drawglx.o differ diff --git a/src/drawglx_internal.o b/src/drawglx_internal.o index 07bd9ae..04ab5b1 100644 Binary files a/src/drawglx_internal.o and b/src/drawglx_internal.o differ diff --git a/src/fontapi.c b/src/fontapi.c index c21e4e7..b759735 100644 --- a/src/fontapi.c +++ b/src/fontapi.c @@ -34,12 +34,21 @@ xoverlay_font_load(const char *path, float size) { struct fontapi_font_t result; memset(&result, 0, sizeof(result)); - strncpy(result.path, path, sizeof(result.path) - 1); - result.size = size; - xoverlay_font_handle_t handle = fontapi_add_font(&result); - log_write("fontapi: init font %u: %d %d\n", handle, loaded_fonts[handle].init, result.init); - fflush(stdout); - return handle; + + result.atlas = texture_atlas_new(1024, 1024, 1); + if (result.atlas != NULL) + { + result.font = texture_font_new_from_file(result.atlas, size, path); + if (result.font == NULL) + { + log_write("fontapi: load: could not init font\n"); + } + } + else + { + log_write("fontapi: load: could not init atlas\n"); + } + return fontapi_add_font(&result); } void @@ -49,8 +58,6 @@ xoverlay_font_unload(xoverlay_font_handle_t handle) return; if (loaded_fonts[handle].init == 0) return; - if (loaded_fonts[handle].loaded == 0) - return; texture_atlas_delete(loaded_fonts[handle].atlas); texture_font_delete(loaded_fonts[handle].font); @@ -59,69 +66,30 @@ xoverlay_font_unload(xoverlay_font_handle_t handle) xoverlay_font_handle_t fontapi_add_font(struct fontapi_font_t *font) { - for (xoverlay_font_handle_t i = 0; i < XOVERLAY_FONT_COUNT; ++i) + for (xoverlay_font_handle_t i = 1; i < XOVERLAY_FONT_COUNT; ++i) { if (loaded_fonts[i].init == 0) { font->init = 1; memcpy(&loaded_fonts[i], font, sizeof(struct fontapi_font_t)); + log_write("init success: %u %p %p\n", i, font->atlas, font->font); return i; } } return XOVERLAY_FONT_INVALID_HANDLE; } -void -fontapi_texture_load(xoverlay_font_handle_t handle) -{ - log_write("fontapi: loading font %u\n", handle); - struct fontapi_font_t *font = &loaded_fonts[handle]; - - font->error = 1; - - font->atlas = texture_atlas_new(1024, 1024, 1); - if (font->atlas != NULL) - { - font->font = texture_font_new_from_file(font->atlas, font->size, font->path); - if (font->font != NULL) - { - font->error = 0; - } - else - { - log_write("fontapi: load: could not init font\n"); - } - } - else - { - log_write("fontapi: load: could not init atlas\n"); - } - - font->loaded = 1; -} - texture_font_t* fontapi_get(xoverlay_font_handle_t handle) { - log_write("fontapi: finding font %u\n", handle); if (handle >= XOVERLAY_FONT_COUNT) { log_write("fontapi: invalid handle %u\n", handle); - fflush(stdout); return NULL; } if (loaded_fonts[handle].init == 0) { - log_write("fontapi: font '%s' %u not init\n", loaded_fonts[handle - 1].path, handle); - fflush(stdout); - return NULL; - } - if (loaded_fonts[handle].loaded == 0) - fontapi_texture_load(handle); - if (loaded_fonts[handle].error == 1) - { - log_write("fontapi: %u loading error\n", handle); - fflush(stdout); + log_write("fontapi: font %u not init\n", handle); return NULL; } return loaded_fonts[handle].font; diff --git a/src/fontapi.o b/src/fontapi.o index 07778dd..4179f54 100644 Binary files a/src/fontapi.o and b/src/fontapi.o differ diff --git a/src/input.o b/src/input.o index b77cca8..7c3cde8 100644 Binary files a/src/input.o and b/src/input.o differ diff --git a/src/log.c b/src/log.c index e5b348c..376e843 100644 --- a/src/log.c +++ b/src/log.c @@ -12,6 +12,8 @@ FILE *log_file = 0; +#if DEBUG + void log_write(const char *format, ...) { @@ -34,3 +36,4 @@ log_write(const char *format, ...) va_end(args); } +#endif diff --git a/src/log.o b/src/log.o index d3360dd..4eaef49 100644 Binary files a/src/log.o and b/src/log.o differ diff --git a/src/overlay.o b/src/overlay.o index 78edb43..1ab2191 100644 Binary files a/src/overlay.o and b/src/overlay.o differ diff --git a/src/program_freetype.o b/src/program_freetype.o index defd43b..78565a8 100644 Binary files a/src/program_freetype.o and b/src/program_freetype.o differ diff --git a/src/program_triangles_plain.o b/src/program_triangles_plain.o index 627ba56..c6ca1f6 100644 Binary files a/src/program_triangles_plain.o and b/src/program_triangles_plain.o differ diff --git a/src/program_triangles_textured.o b/src/program_triangles_textured.o index 00e62d4..314b835 100644 Binary files a/src/program_triangles_textured.o and b/src/program_triangles_textured.o differ diff --git a/src/programs.o b/src/programs.o index c14b360..cce1803 100644 Binary files a/src/programs.o and b/src/programs.o differ diff --git a/src/textureapi.o b/src/textureapi.o index 7b11ebf..2c4a5ac 100644 Binary files a/src/textureapi.o and b/src/textureapi.o differ