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