libdrawtext
view examples/simple/simple.c @ 88:e12e0bdfa7f1
merged font2glyphmap changes
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 17 Apr 2014 06:57:53 +0300 |
parents | |
children |
line source
1 /* Simple libdrawtext example.
2 *
3 * Important parts are marked with XXX comments.
4 */
5 #include <stdio.h>
6 #include <stdlib.h>
8 #ifndef __APPLE__
9 #include <GL/glut.h>
10 #else
11 #include <GLUT/glut.h>
12 #endif
14 #include "drawtext.h"
16 void disp(void);
17 void reshape(int x, int y);
18 void keyb(unsigned char key, int x, int y);
20 /* XXX fonts are represented by the opaque struct dtx_font type, so you
21 * need to create at least one with dtx_open_font (see main).
22 */
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 dtx_open_font opens a font file and returns a pointer to dtx_font */
37 if(!(font = dtx_open_font("serif.ttf", 24))) {
38 fprintf(stderr, "failed to open font\n");
39 return 1;
40 }
41 /* XXX select the font and size to render with by calling dtx_use_font
42 * if you want to use a different font size, you must first call:
43 * dtx_prepare(font, size) once.
44 */
45 dtx_use_font(font, 24);
47 glutMainLoop();
48 return 0;
49 }
51 const char *text = "Some sample text goes here.\n"
52 "Yada yada yada, more text...\n"
53 "foobar xyzzy\n";
55 void disp(void)
56 {
57 glClear(GL_COLOR_BUFFER_BIT);
59 glMatrixMode(GL_MODELVIEW);
60 glLoadIdentity();
62 glPushMatrix();
63 glTranslatef(-200, 150, 0);
64 glColor3f(1, 1, 1);
65 /* XXX call dtx_string to draw utf-8 text.
66 * any transformations and the current color apply
67 */
68 dtx_string(text);
69 glPopMatrix();
71 glPushMatrix();
72 glTranslatef(-200, 50, 0);
73 glScalef(2, 0.7, 1);
74 glColor3f(0.6, 0.7, 1.0);
75 dtx_string(text);
76 glPopMatrix();
78 glPushMatrix();
79 glTranslatef(-80, -90, 0);
80 glRotatef(20, 0, 0, 1);
81 glColor3f(1.0, 0.7, 0.6);
82 dtx_string(text);
83 glPopMatrix();
85 glutSwapBuffers();
86 }
88 void reshape(int x, int y)
89 {
90 glViewport(0, 0, x, y);
92 glMatrixMode(GL_PROJECTION);
93 glLoadIdentity();
94 glOrtho(-x/2, x/2, -y/2, y/2, -1, 1);
95 }
97 void keyb(unsigned char key, int x, int y)
98 {
99 if(key == 27) {
100 exit(0);
101 }
102 }