I was eager to learn game programming for a while, so I started my research on SDL. The first article "SDL Study Notes: pictures and font display" was written in March July, so far, it stops.
I have been enthusiastic about the recent period of time, pick up the previous code, and continue to study! I did not find a Chinese display method when I wrote the text "SDL learning notes 1 image and font display". Today, refer to "SDL & Object Pascal (Delphi) [2] show Chinese characters. It's just the beginning of a new study when you move a kid!
Below is the code, also using Delphi7, with JEDI-SDL:
1 program project1;
2
3 uses
4 sysutils,
5 SDL,
6 sdl_ttf;
7
8var
9 screen: psdl_surface;
10 event: tsdl_event;
11 Font: pttf_font;
12 outtxt: widestring;
13 procedure draw_unicode_text (word: widestring; x_pos, y_pos: integer;
14 color: Cardinal );
15var
16 text: psdl_surface;
17 DEST: tsdl_rect;
18 CLR: tsdl_color;
19 begin
20 CLR. R: = color and $ ff;
21 CLR. G: = (color SHR 8) and $ ff;
22 CLR. B: = (color SHR 16) and $ ff;
23 // two global objects screen and font are used
24 text: = ttf_renderunicode_blended (font, @ word [1], CLR );
25 DeST. X: = x_pos;
26 DeST. Y: = y_pos;
27 sdl_blitsurface (text, nil, screen, @ DEST );
28 sdl_freesurface (text );
29end;
30 begin
31 if sdl_init (sdl_init_video) <0 Then exit;
32 If ttf_init () <0 Then exit;
33 sdl_wm_setcaption ('delphi SDL demo', nil );
34 screen: = sdl_setvideomode (640,480, 32, sdl_swsurface );
35 if (screen = nil) then
36 begin
37 sdl_quit;
38 exit;
39 end;
40 Font: = ttf_openfont ('msyh. ttf', 24 );
41 outtxt: = 'jedi-SDL demo ';
42 draw_unicode_text (outtxt, 220,160, $ 0000ff );
43 draw_unicode_text ('sdl Chinese output test', 220,200, $336699 );
44 draw_unicode_text ('Code by shaoyun', 220,240, $00ff00 );
45 sdl_flip (screen );
46 While sdl_pollevent (@ event)> = 0 do
47 begin
48 case event. Type _
49 sdl_quitev: break;
50 sdl_keydown:
51 case event. Key. keysym. sym
52 sdlk_escape: break;
53 end;
54 end;
55 end;
56 ttf_closefont (font );
57 ttf_quit;
58 sdl_quit;
59 exit;
60end.