|
发表于 2004-5-22 14:41:04
|
显示全部楼层
硬盘已经恢复!下边是显示TrueType字体的示例代码:
[code:1]
/* showhz.c writed by lanche, 2004.05.21 */
/* http://linside.8u8.com | [email protected] */
#include <SDL.h>
#include <SDL_ttf.h>
int main()
{
SDL_Surface *screen;
SDL_Event event;
TTF_Font *font;
SDL_Surface *text;
int ptsize;
SDL_Color white={255,255,255,0};
// Initialize SDL
if(SDL_Init(SDL_INIT_VIDEO)<0){
fprintf(stderr,"Can't init SDL:%s\n",SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen=SDL_SetVideoMode(640,480,16,SDL_SWSURFACE);
if(screen==NULL){
fprintf(stderr,"Can't set mode 640x480:%s\n",SDL_GetError());
exit(1);
}
SDL_ShowCursor(0);
// Initialize the TTF library
if(TTF_Init()<0){
fprintf(stderr,"Couldn't initialize TTF: %s\n",SDL_GetError());
exit(1);
}
atexit(TTF_Quit);
SDL_FillRect(screen,NULL,(SDL_MapRGB(screen->format,8,40,130)));
SDL_UpdateRect(screen,0,0,0,0);
ptsize=64;
font=TTF_OpenFont("/usr/fonts/truetype/simsun.ttf",ptsize);
text=TTF_RenderUTF8_Blended(font,"TrueType字体显示",white);
SDL_BlitSurface(text,NULL,screen,NULL);
SDL_UpdateRect(screen,0,0,0,0);
for(;;){
SDL_WaitEvent(&event);
if(event.type==SDL_KEYDOWN)break;
}
TTF_CloseFont(font);
SDL_FreeSurface(text);
SDL_Quit();
}
[/code:1]
编译:gcc -I/usr/include/SDL -lSDL -lSDL_ttf showhz.c -o showhz
运行:./showhz
注意:代码要用kwrite或其它编辑器转存成utf8格式才能正确显示中文。 |
|