libdrawtext
diff examples/unicode/unicode.c @ 4:17fed026b24b
done with the unicode sample
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Fri, 16 Sep 2011 08:31:06 +0300 |
parents | fe0c54e574ae |
children | 10cfb642d0b8 |
line diff
1.1 --- a/examples/unicode/unicode.c Thu Sep 15 23:32:39 2011 +0300 1.2 +++ b/examples/unicode/unicode.c Fri Sep 16 08:31:06 2011 +0300 1.3 @@ -20,40 +20,47 @@ 1.4 /* XXX fonts are represented by the opaque struct dtx_font type, so you 1.5 * need to create at least one with dtx_open_font (see main). 1.6 */ 1.7 -struct dtx_font *freeserif, *klingon; 1.8 +struct dtx_font *fntmain, *fntcjk, *fntklingon; 1.9 1.10 -#define FONT_SIZE 24 1.11 +#define FONT_SZ 24 1.12 1.13 int main(int argc, char **argv) 1.14 { 1.15 glutInit(&argc, argv); 1.16 glutInitWindowSize(512, 384); 1.17 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 1.18 - glutCreateWindow("libdrawtext example: simple"); 1.19 + glutCreateWindow("libdrawtext example: unicode"); 1.20 1.21 glutDisplayFunc(disp); 1.22 glutReshapeFunc(reshape); 1.23 glutKeyboardFunc(keyb); 1.24 1.25 /* XXX dtx_open_font opens a font file and returns a pointer to dtx_font */ 1.26 - if(!(freeserif = dtx_open_font("serif.ttf", 0))) { 1.27 + if(!(fntmain = dtx_open_font("serif.ttf", 0))) { 1.28 return 1; 1.29 } 1.30 - dtx_prepare_range(freeserif, FONT_SIZE, 0, 256); /* prepare ASCII */ 1.31 - dtx_prepare_range(freeserif, FONT_SIZE, 0x0370, 0x0400); /* greek */ 1.32 - dtx_prepare_range(freeserif, FONT_SIZE, 0x4e00, 0x9fc0); /* kanji */ 1.33 + dtx_prepare_range(fntmain, FONT_SZ, 0, 256); /* ASCII */ 1.34 + dtx_prepare_range(fntmain, FONT_SZ, 0x370, 0x400); /* greek */ 1.35 + dtx_prepare_range(fntmain, FONT_SZ, 0x400, 0x500); /* cyrilic */ 1.36 1.37 - if(!(klingon = dtx_open_font("klingon.ttf", 0))) { 1.38 + if(!(fntcjk = dtx_open_font("cjk.ttf", 0))) { 1.39 return 1; 1.40 } 1.41 - dtx_prepare_range(klingon, FONT_SIZE, 0xf8d0, 0xf900); 1.42 + dtx_prepare_range(fntcjk, FONT_SZ, 0x4e00, 0x9fc0); /* kanji */ 1.43 + 1.44 + if(!(fntklingon = dtx_open_font("klingon.ttf", 0))) { 1.45 + return 1; 1.46 + } 1.47 + dtx_prepare_range(fntklingon, FONT_SZ, 0xf8d0, 0xf900); /* klingon */ 1.48 1.49 glutMainLoop(); 1.50 return 0; 1.51 } 1.52 1.53 -const char *ascii_text = "Hello world!"; 1.54 +/* various UTF-8 strings */ 1.55 +const char *english_text = "Hello world!"; 1.56 const char *greek_text = "\xce\x9a\xce\xbf\xcf\x8d\xcf\x81\xce\xb1\xcf\x83\xce\xb7"; 1.57 +const char *russian_text = "\xd0\xa0\xd0\xb0\xd1\x81\xd1\x86\xd0\xb2\xd0\xb5\xd1\x82\xd0\xb0\xd0\xbb\xd0\xb8 \xd1\x8f\xd0\xb1\xd0\xbb\xd0\xbe\xd0\xbd\xd0\xb8 \xd0\xb8 \xd0\xb3\xd1\x80\xd1\x83\xd1\x88\xd0\xb8"; 1.58 const char *kanji_text = "\xe4\xb9\x97\xe4\xba\xac"; 1.59 const char *klingon_text = "\xef\xa3\xa3\xef\xa3\x9d\xef\xa3\x93\xef\xa3\x98\xef\xa3\x9d\xef\xa3\xa2\xef\xa3\xa1\xef\xa3\x9d\xef\xa3\x99"; 1.60 1.61 @@ -65,21 +72,26 @@ 1.62 glMatrixMode(GL_MODELVIEW); 1.63 glLoadIdentity(); 1.64 1.65 - dtx_use_font(freeserif, FONT_SIZE); 1.66 + dtx_use_font(fntmain, FONT_SZ); 1.67 1.68 glTranslatef(-200, 150, 0); 1.69 /* XXX call dtx_string to draw utf-8 text. 1.70 * any transformations and the current color apply 1.71 */ 1.72 - dtx_string(ascii_text); 1.73 + dtx_string(english_text); 1.74 1.75 glTranslatef(0, -40, 0); 1.76 dtx_string(greek_text); 1.77 1.78 glTranslatef(0, -40, 0); 1.79 + dtx_string(russian_text); 1.80 + 1.81 + dtx_use_font(fntcjk, FONT_SZ); 1.82 + 1.83 + glTranslatef(0, -40, 0); 1.84 dtx_string(kanji_text); 1.85 1.86 - dtx_use_font(klingon, FONT_SIZE); 1.87 + dtx_use_font(fntklingon, FONT_SZ); 1.88 1.89 glTranslatef(0, -40, 0); 1.90 dtx_string(klingon_text);