rev |
line source |
nuclear@22
|
1 /* Simple libdrawtext example without freetype.
|
nuclear@22
|
2 */
|
nuclear@22
|
3 #include <stdio.h>
|
nuclear@22
|
4 #include <stdlib.h>
|
nuclear@22
|
5
|
nuclear@22
|
6 #ifndef __APPLE__
|
nuclear@22
|
7 #include <GL/glut.h>
|
nuclear@22
|
8 #else
|
nuclear@22
|
9 #include <GLUT/glut.h>
|
nuclear@22
|
10 #endif
|
nuclear@22
|
11
|
nuclear@22
|
12 #include "drawtext.h"
|
nuclear@22
|
13
|
nuclear@22
|
14 void disp(void);
|
nuclear@22
|
15 void reshape(int x, int y);
|
nuclear@22
|
16 void keyb(unsigned char key, int x, int y);
|
nuclear@22
|
17
|
nuclear@22
|
18 struct dtx_font *font;
|
nuclear@22
|
19
|
nuclear@22
|
20 int main(int argc, char **argv)
|
nuclear@22
|
21 {
|
nuclear@22
|
22 glutInit(&argc, argv);
|
nuclear@22
|
23 glutInitWindowSize(512, 384);
|
nuclear@22
|
24 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
|
nuclear@22
|
25 glutCreateWindow("libdrawtext example: simple");
|
nuclear@22
|
26
|
nuclear@22
|
27 glutDisplayFunc(disp);
|
nuclear@22
|
28 glutReshapeFunc(reshape);
|
nuclear@22
|
29 glutKeyboardFunc(keyb);
|
nuclear@22
|
30
|
nuclear@22
|
31 if(!(font = dtx_open_font_glyphmap("serif_s24.glyphmap"))) {
|
nuclear@22
|
32 fprintf(stderr, "failed to open font\n");
|
nuclear@22
|
33 return 1;
|
nuclear@22
|
34 }
|
nuclear@22
|
35 dtx_use_font(font, 24);
|
nuclear@22
|
36
|
nuclear@22
|
37 glutMainLoop();
|
nuclear@22
|
38 return 0;
|
nuclear@22
|
39 }
|
nuclear@22
|
40
|
nuclear@22
|
41 const char *text = "Some sample text goes here.\n"
|
nuclear@22
|
42 "Yada yada yada, more text...\n"
|
nuclear@22
|
43 "foobar xyzzy\n";
|
nuclear@22
|
44
|
nuclear@22
|
45 void disp(void)
|
nuclear@22
|
46 {
|
nuclear@22
|
47 glClear(GL_COLOR_BUFFER_BIT);
|
nuclear@22
|
48
|
nuclear@22
|
49 glMatrixMode(GL_MODELVIEW);
|
nuclear@22
|
50 glLoadIdentity();
|
nuclear@22
|
51
|
nuclear@22
|
52 glPushMatrix();
|
nuclear@22
|
53 glTranslatef(-200, 150, 0);
|
nuclear@22
|
54 glColor3f(1, 1, 1);
|
nuclear@22
|
55 /* XXX call dtx_string to draw utf-8 text.
|
nuclear@22
|
56 * any transformations and the current color apply
|
nuclear@22
|
57 */
|
nuclear@22
|
58 dtx_string(text);
|
nuclear@22
|
59 glPopMatrix();
|
nuclear@22
|
60
|
nuclear@22
|
61 glPushMatrix();
|
nuclear@22
|
62 glTranslatef(-200, 50, 0);
|
nuclear@22
|
63 glScalef(2, 0.7, 1);
|
nuclear@22
|
64 glColor3f(0.6, 0.7, 1.0);
|
nuclear@22
|
65 dtx_string(text);
|
nuclear@22
|
66 glPopMatrix();
|
nuclear@22
|
67
|
nuclear@22
|
68 glPushMatrix();
|
nuclear@22
|
69 glTranslatef(-80, -90, 0);
|
nuclear@22
|
70 glRotatef(20, 0, 0, 1);
|
nuclear@22
|
71 glColor3f(1.0, 0.7, 0.6);
|
nuclear@22
|
72 dtx_string(text);
|
nuclear@22
|
73 glPopMatrix();
|
nuclear@22
|
74
|
nuclear@22
|
75 glutSwapBuffers();
|
nuclear@22
|
76 }
|
nuclear@22
|
77
|
nuclear@22
|
78 void reshape(int x, int y)
|
nuclear@22
|
79 {
|
nuclear@22
|
80 glViewport(0, 0, x, y);
|
nuclear@22
|
81
|
nuclear@22
|
82 glMatrixMode(GL_PROJECTION);
|
nuclear@22
|
83 glLoadIdentity();
|
nuclear@22
|
84 glOrtho(-x/2, x/2, -y/2, y/2, -1, 1);
|
nuclear@22
|
85 }
|
nuclear@22
|
86
|
nuclear@22
|
87 void keyb(unsigned char key, int x, int y)
|
nuclear@22
|
88 {
|
nuclear@22
|
89 if(key == 27) {
|
nuclear@22
|
90 exit(0);
|
nuclear@22
|
91 }
|
nuclear@22
|
92 }
|