- added libdrawtext
[demo_prior] / src / imtk / imtk.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <assert.h>
6 #include "opengl.h"
7 #include "imtk.h"
8 #include "state.h"
9 #include "draw.h"
10
11 void imtk_post_redisplay(void)
12 {
13         glutPostRedisplay();
14 }
15
16 void imtk_begin(void)
17 {
18         int width, height;
19
20         glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
21
22         glDisable(GL_DEPTH_TEST);
23         glDisable(GL_STENCIL_TEST);
24         glDisable(GL_ALPHA_TEST);
25         glDisable(GL_TEXTURE_1D);
26         glDisable(GL_TEXTURE_2D);
27         glDisable(GL_CULL_FACE);
28         glDisable(GL_SCISSOR_TEST);
29         glDisable(GL_LIGHTING);
30         glEnable(GL_BLEND);
31         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
32
33
34         imtk_get_viewport(&width, &height);
35
36         glMatrixMode(GL_PROJECTION);
37         glPushMatrix();
38         glLoadIdentity();
39         glTranslatef(-1, 1, 0);
40         glScalef(2.0 / width, -2.0 / height, 1.0);
41
42         glMatrixMode(GL_MODELVIEW);
43         glPushMatrix();
44         glLoadIdentity();
45 }
46
47 void imtk_end(void)
48 {
49         glMatrixMode(GL_PROJECTION);
50         glPopMatrix();
51         glMatrixMode(GL_MODELVIEW);
52         glPopMatrix();
53
54         glPopAttrib();
55 }
56
57 void imtk_label(const char *str, int x, int y)
58 {
59         if(x == IMTK_AUTO || y == IMTK_AUTO) {
60                 imtk_layout_get_pos(&x, &y);
61         }
62
63         glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
64         imtk_draw_string(x, y + 14, str);
65         imtk_layout_advance(imtk_string_size(str), 12);
66 }