69,371
社区成员
发帖
与我相关
我的任务
分享
void rest_remander(void){
//初始化SDL
SDL_Surface *screen;
Uint32 color;
if(SDL_Init(SDL_INIT_VIDEO)<0){
//fprintf(stderr,"无法初始化SDL:%s\n",SDL_GetError);
//exit(1);
writeLog("无法初始化SDL");
return;
}
screen = SDL_SetVideoMode(640,480,16,SDL_SWSURFACE);
if(screen==NULL){
//fprintf(stderr,"无法设置640*480,16位色的视频模式:%s\n",SDL_GetError);
//exit(1);
writeLog("无法设置视频模式");
return;
}
atexit(SDL_Quit);
//初始化TTF库
if( TTF_Init() == -1){
writeLog("初始化TTF库失败");
return -1;
}
//创建一个对应某字体文件的TTF_Font
TTF_Font *font;
font = TTF_OpenFont("/usr/local/share/fonts/simfang.ttf",16);
if(!font){
printf("TTF_OpenFont:Open /usr/local/share/fonts/simfang.ttf %s\n", TTF_GetError());
writeLog("创建字体失败");
return -1;
}
//设置字体颜色
SDL_Color textColor = {255, 255, 255};
SDL_Surface * message;
message = TTF_RenderText_Solid( font, "注意休息", textColor);
if(message){
apply_surface(0,0,message,screen);
}
//刷新屏幕
if(SDL_Flip(screen) == -1){
writeLog("刷新屏幕失败");
return -2;
}
SDL_Delay(2000);
SDL_FreeSurface(message);
//释放字体
TTF_CloseFont( font );
TTF_Quit();
return ;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ){
//Temporary rectangle to hold the offsets
SDL_Rect offset;
//Get the offsets
offset.x = x;
offset.y = y;
//Blit the surface
SDL_BlitSurface( source, NULL, destination, &offset );
}