如題,實在是找了好久,都沒找到好的例子。自己對照寫的也莫名奇妙的退出了
這是我寫的代碼(功能是彈出一個視窗,上面顯示注意休息)懂得老哥幫忙看下,能寫個demo更好了:
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 );
}
uj5u.com熱心網友回復:
里面的writeLog()作用是寫日志轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/35874.html
標籤:C語言
上一篇:關于二叉樹的建立
下一篇:求解答
