libdrawtext
view examples/nofreetype/simple-noft.c @ 31:bc85a35d88d7
cleaned up the comments in examples/nofreetype
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 15 Apr 2014 06:00:16 +0300 |
parents | df6d52b36bd6 |
children |
line source
1 /* The "simple" example, modified to use a pre-built glyphmap instead of using freetype.
2 * This can be used when using libdrawtext-noft (built without freetype support/dependency).
3 *
4 * There is only one difference between this, and the regular usage demonstrated in
5 * examples/simple, and it's marked with an XXX comment in the code. For the rest of
6 * the details of libdrawtext usage in this code, refer to examples/simple/simple.c.
7 */
8 #include <stdio.h>
9 #include <stdlib.h>
11 #ifndef __APPLE__
12 #include <GL/glut.h>
13 #else
14 #include <GLUT/glut.h>
15 #endif
17 #include "drawtext.h"
19 void disp(void);
20 void reshape(int x, int y);
21 void keyb(unsigned char key, int x, int y);
23 struct dtx_font *font;
25 int main(int argc, char **argv)
26 {
27 glutInit(&argc, argv);
28 glutInitWindowSize(512, 384);
29 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
30 glutCreateWindow("libdrawtext example: simple");
32 glutDisplayFunc(disp);
33 glutReshapeFunc(reshape);
34 glutKeyboardFunc(keyb);
36 /* XXX: only difference is that we have to call dtx_open_font_glyphmap,
37 * instead of dtx_open_font, passing it the filename of a pre-built
38 * glyphmap (see tools/font2glyphmap).
39 */
40 if(!(font = dtx_open_font_glyphmap("serif_s24.glyphmap"))) {
41 fprintf(stderr, "failed to open font\n");
42 return 1;
43 }
44 dtx_use_font(font, 24);
46 glutMainLoop();
47 return 0;
48 }
50 const char *text = "Some sample text goes here.\n"
51 "Yada yada yada, more text...\n"
52 "foobar xyzzy\n";
54 void disp(void)
55 {
56 glClear(GL_COLOR_BUFFER_BIT);
58 glMatrixMode(GL_MODELVIEW);
59 glLoadIdentity();
61 glPushMatrix();
62 glTranslatef(-200, 150, 0);
63 glColor3f(1, 1, 1);
64 dtx_string(text);
65 glPopMatrix();
67 glPushMatrix();
68 glTranslatef(-200, 50, 0);
69 glScalef(2, 0.7, 1);
70 glColor3f(0.6, 0.7, 1.0);
71 dtx_string(text);
72 glPopMatrix();
74 glPushMatrix();
75 glTranslatef(-80, -90, 0);
76 glRotatef(20, 0, 0, 1);
77 glColor3f(1.0, 0.7, 0.6);
78 dtx_string(text);
79 glPopMatrix();
81 glutSwapBuffers();
82 }
84 void reshape(int x, int y)
85 {
86 glViewport(0, 0, x, y);
88 glMatrixMode(GL_PROJECTION);
89 glLoadIdentity();
90 glOrtho(-x/2, x/2, -y/2, y/2, -1, 1);
91 }
93 void keyb(unsigned char key, int x, int y)
94 {
95 if(key == 27) {
96 exit(0);
97 }
98 }