libdrawtext
diff examples/nofreetype/simple-noft.c @ 74:838d473cf6cc
- properly supported building of no-freetype version, separately installed as libdrawtext-noft.whatever
- saving/loading glyphmaps now work correctly
- added nofreetype program in examples, to illustrate how to use libdrawtext-noft with prebuilt glyphmaps (see tools/font2glyphmap)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 15 Apr 2014 05:10:39 +0300 |
parents | |
children | bc85a35d88d7 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/examples/nofreetype/simple-noft.c Tue Apr 15 05:10:39 2014 +0300 1.3 @@ -0,0 +1,92 @@ 1.4 +/* Simple libdrawtext example without freetype. 1.5 + */ 1.6 +#include <stdio.h> 1.7 +#include <stdlib.h> 1.8 + 1.9 +#ifndef __APPLE__ 1.10 +#include <GL/glut.h> 1.11 +#else 1.12 +#include <GLUT/glut.h> 1.13 +#endif 1.14 + 1.15 +#include "drawtext.h" 1.16 + 1.17 +void disp(void); 1.18 +void reshape(int x, int y); 1.19 +void keyb(unsigned char key, int x, int y); 1.20 + 1.21 +struct dtx_font *font; 1.22 + 1.23 +int main(int argc, char **argv) 1.24 +{ 1.25 + glutInit(&argc, argv); 1.26 + glutInitWindowSize(512, 384); 1.27 + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 1.28 + glutCreateWindow("libdrawtext example: simple"); 1.29 + 1.30 + glutDisplayFunc(disp); 1.31 + glutReshapeFunc(reshape); 1.32 + glutKeyboardFunc(keyb); 1.33 + 1.34 + if(!(font = dtx_open_font_glyphmap("serif_s24.glyphmap"))) { 1.35 + fprintf(stderr, "failed to open font\n"); 1.36 + return 1; 1.37 + } 1.38 + dtx_use_font(font, 24); 1.39 + 1.40 + glutMainLoop(); 1.41 + return 0; 1.42 +} 1.43 + 1.44 +const char *text = "Some sample text goes here.\n" 1.45 + "Yada yada yada, more text...\n" 1.46 + "foobar xyzzy\n"; 1.47 + 1.48 +void disp(void) 1.49 +{ 1.50 + glClear(GL_COLOR_BUFFER_BIT); 1.51 + 1.52 + glMatrixMode(GL_MODELVIEW); 1.53 + glLoadIdentity(); 1.54 + 1.55 + glPushMatrix(); 1.56 + glTranslatef(-200, 150, 0); 1.57 + glColor3f(1, 1, 1); 1.58 + /* XXX call dtx_string to draw utf-8 text. 1.59 + * any transformations and the current color apply 1.60 + */ 1.61 + dtx_string(text); 1.62 + glPopMatrix(); 1.63 + 1.64 + glPushMatrix(); 1.65 + glTranslatef(-200, 50, 0); 1.66 + glScalef(2, 0.7, 1); 1.67 + glColor3f(0.6, 0.7, 1.0); 1.68 + dtx_string(text); 1.69 + glPopMatrix(); 1.70 + 1.71 + glPushMatrix(); 1.72 + glTranslatef(-80, -90, 0); 1.73 + glRotatef(20, 0, 0, 1); 1.74 + glColor3f(1.0, 0.7, 0.6); 1.75 + dtx_string(text); 1.76 + glPopMatrix(); 1.77 + 1.78 + glutSwapBuffers(); 1.79 +} 1.80 + 1.81 +void reshape(int x, int y) 1.82 +{ 1.83 + glViewport(0, 0, x, y); 1.84 + 1.85 + glMatrixMode(GL_PROJECTION); 1.86 + glLoadIdentity(); 1.87 + glOrtho(-x/2, x/2, -y/2, y/2, -1, 1); 1.88 +} 1.89 + 1.90 +void keyb(unsigned char key, int x, int y) 1.91 +{ 1.92 + if(key == 27) { 1.93 + exit(0); 1.94 + } 1.95 +}