# HG changeset patch # User John Tsiombikas # Date 1362070293 -7200 # Node ID 982f2464b8a78d6e262b5ffa9523a2d1770ba042 # Parent 1c2c00d432dac02cc8dfc7782e48c27a3cf7ea97 added dtx_printf diff -r 1c2c00d432da -r 982f2464b8a7 examples/Makefile --- a/examples/Makefile Sun Aug 26 04:43:09 2012 +0300 +++ b/examples/Makefile Thu Feb 28 18:51:33 2013 +0200 @@ -12,6 +12,7 @@ cd linlibertine; tar xzvf ../LinLibertineTTF_5.1.3_2011_06_21.tgz rm -f LinLibertineTTF_5.1.3_2011_06_21.tgz cp linlibertine/LinLibertine_R.ttf $@ + rm -rf linlibertine fonts/sazanami-mincho.ttf: mkdir -p fonts @@ -19,6 +20,7 @@ tar xjvf sazanami-20040629.tar.bz2 rm -f sazanami-20040629.tar.bz2 cp sazanami-20040629/sazanami-mincho.ttf $@ + rm -rf sazanami-20040629 fonts/klingon.ttf: mkdir -p fonts @@ -26,3 +28,4 @@ unzip -o tlh_2D00_pIqaD_2D00_US.zip rm -f tlh_2D00_pIqaD_2D00_US.zip cp tlh-pIqaD-US/pIqaD.ttf $@ + rm -rf tlh-pIqaD-US diff -r 1c2c00d432da -r 982f2464b8a7 src/drawgl.c --- a/src/drawgl.c Sun Aug 26 04:43:09 2012 +0300 +++ b/src/drawgl.c Thu Feb 28 18:51:33 2013 +0200 @@ -16,6 +16,7 @@ along with this program. If not, see . */ #ifndef NO_OPENGL +#include #include #include @@ -117,9 +118,31 @@ dtx_flush(); } +static const char *put_char(const char *str, float *pos_x, float *pos_y, int *should_flush) +{ + struct dtx_glyphmap *gmap; + float px, py; + int code = dtx_utf8_char_code(str); + str = dtx_utf8_next_char((char*)str); + + if(buf_mode == DTX_LBF && code == '\n') { + *should_flush = 1; + } + + px = *pos_x; + py = *pos_y; + + if((gmap = dtx_proc_char(code, pos_x, pos_y))) { + int idx = code - gmap->cstart; + + set_glyphmap_texture(gmap); + add_glyph(gmap->glyphs + idx, px, py); + } + return str; +} + void dtx_string(const char *str) { - struct dtx_glyphmap *gmap; int should_flush = buf_mode == DTX_NBF; float pos_x = 0.0f; float pos_y = 0.0f; @@ -129,23 +152,7 @@ } while(*str) { - float px, py; - int code = dtx_utf8_char_code(str); - str = dtx_utf8_next_char((char*)str); - - if(buf_mode == DTX_LBF && code == '\n') { - should_flush = 1; - } - - px = pos_x; - py = pos_y; - - if((gmap = dtx_proc_char(code, &pos_x, &pos_y))) { - int idx = code - gmap->cstart; - - set_glyphmap_texture(gmap); - add_glyph(gmap->glyphs + idx, px, py); - } + str = put_char(str, &pos_x, &pos_y, &should_flush); } if(should_flush) { @@ -153,6 +160,32 @@ } } +void dtx_printf(const char *fmt, ...) +{ + va_list ap; + int buf_size; + char *buf, tmp; + + if(!dtx_font) { + return; + } + + va_start(ap, fmt); + buf_size = vsnprintf(&tmp, 0, fmt, ap); + va_end(ap); + + if(buf_size == -1) { + buf_size = 512; + } + + buf = alloca(buf_size + 1); + va_start(ap, fmt); + vsnprintf(buf, buf_size + 1, fmt, ap); + va_end(ap); + + dtx_string(buf); +} + static void qvertex(struct vertex *v, float x, float y, float s, float t) { v->x = x; diff -r 1c2c00d432da -r 982f2464b8a7 src/drawtext.h --- a/src/drawtext.h Sun Aug 26 04:43:09 2012 +0300 +++ b/src/drawtext.h Thu Feb 28 18:51:33 2013 +0200 @@ -116,6 +116,8 @@ /* draws a utf-8 string starting at the origin. \n \r and \t are handled appropriately. */ void dtx_string(const char *str); +void dtx_printf(const char *fmt, ...); + /* render any pending glyphs (see dtx_draw_buffering) */ void dtx_flush(void);