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(WIN32) || defined(__WIN32__)
27 #include "drawtext_impl.h"
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_string(const char *str)
50 dtx_substring(str, 0, strlen(str));
53 void dtx_substring(const char *str, int start, int end)
55 int should_flush = dtx_buf_mode == DTX_NBF;
56 float pos_x = dtx_cur_offset[0];
57 float pos_y = dtx_cur_offset[1];
63 /* skip start characters */
64 while(*str && start > 0) {
65 str = dtx_utf8_next_char((char*)str);
70 while(*str && --end >= 0) {
71 str = dtx_drawchar(str, &pos_x, &pos_y, &should_flush);
79 void dtx_printf(const char *fmt, ...)
90 buf_size = vsnprintf(&tmp, 0, fmt, ap);
97 buf = alloca(buf_size + 1);
99 vsnprintf(buf, buf_size + 1, fmt, ap);