曾今一段時間熱心的想學習游戲編程於是研究起了SDL第一篇文章《SDL學習筆記一 圖片和字體顯示》是年月份寫的至此之後就停了下來
最近的一段時間有熱心起來拾起以前的代碼繼續研究!寫《SDL學習筆記一 圖片和字體顯示》一文時我沒有找到中文的顯示方法今天參照《SDL & Object Pascal (Delphi) [] 顯示中文字符》一文做了個小鬼搬家也算重新學習的開始吧!
下面是代碼同樣使用Delphi配合JEDISDL
program Project;
uses
SysUtils
SDL
SDL_TTF;
var
screen:PSDL_Surface;
event:TSDL_Event;
font: PTTF_Font;
outtxt: WideString;
procedure draw_unicode_text(word: WideString ; x_posy_pos : Integer;
color :Cardinal);
var
text : PSDL_Surface;
dest : TSDL_Rect;
clr : TSDL_color;
begin
clrr := Color and $FF;
clrg := (Color shr ) and $FF;
clrb := (Color shr ) and $FF;
// 用到了兩個全局對象screen和font
text:= TTF_RenderUNICODE_Blended(font@word[]clr);
destx:=x_pos;
desty:=y_pos;
SDL_BlitSurface(textnilscreen@dest);
SDL_FreeSurface(text);
end;
begin
if SDL_Init(SDL_INIT_VIDEO)< then Exit;
if TTF_Init()< then Exit;
SDL_WM_SetCaption(Delphi SDL Demonil);
screen:=SDL_SetVideoMode(SDL_SWSURFACE);
if (screen=nil) then
begin
SDL_Quit;
exit;
end;
font:=TTF_OpenFont(f);
outtxt:=JEDISDL 演示程序;
draw_unicode_text(outtxt$FF);
draw_unicode_text(SDL中文輸出測試$);
draw_unicode_text(Code By Shaoyun$FF);
SDL_Flip(screen);
while SDL_PollEvent(@event)>= do
begin
case eventtype_ of
SDL_QUITEV: Break;
SDL_KEYDOWN:
case eventkeykeysymsym of
SDLK_ESCAPE: Break;
end;
end;
end;
TTF_CloseFont(font);
TTF_Quit;
SDL_Quit;
exit;
end
From:http://tw.wingwit.com/Article/program/Delphi/201311/24660.html