libdrawtext

annotate examples/nofreetype/simple-noft.c @ 83:00eb0d7aced6

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