2 libdrawtext - a simple library for fast text rendering in OpenGL
3 Copyright (C) 2011-2016 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #if defined(__WATCOMC__) || defined(_WIN32) || defined(__DJGPP__)
29 void dtx_position(float x, float y)
31 dtx_cur_offset[0] = x;
32 dtx_cur_offset[1] = y;
35 void dtx_color(float r, float g, float b, float a)
42 dtx_cur_color_int[0] = r > 1.0 ? 255 : (int)(r * 255.0);
43 dtx_cur_color_int[1] = g > 1.0 ? 255 : (int)(g * 255.0);
44 dtx_cur_color_int[2] = b > 1.0 ? 255 : (int)(b * 255.0);
45 dtx_cur_color_int[3] = a > 1.0 ? 255 : (int)(a * 255.0);
48 void dtx_draw_buffering(int mode)
50 if(mode >= DTX_NBF && mode <= DTX_FBF) {
55 void dtx_string(const char *str)
57 dtx_substring(str, 0, strlen(str));
60 void dtx_substring(const char *str, int start, int end)
62 int should_flush = dtx_buf_mode == DTX_NBF;
63 float pos_x = dtx_cur_offset[0];
64 float pos_y = dtx_cur_offset[1];
70 /* skip start characters */
71 while(*str && start > 0) {
72 str = dtx_utf8_next_char((char*)str);
77 while(*str && --end >= 0) {
78 str = dtx_drawchar(str, &pos_x, &pos_y, &should_flush);
86 #if defined(_MSC_VER) || defined(__WATCOMC__)
87 #define vsnprintf _vsnprintf
90 void dtx_printf(const char *fmt, ...)
101 buf_size = vsnprintf(&tmp, 0, fmt, ap);
108 buf = alloca(buf_size + 1);
110 vsnprintf(buf, buf_size + 1, fmt, ap);