2012-01-04 42 views
1

即時通訊使用的代碼塊,我已經安裝圖書館,並沒有錯誤那裏... 當我建立項目,編譯器說,它沒有錯誤,當我運行它它只是會彈出一個窗口和內部它只是黑色的,而其假設出現的話「世界報HOLA ......」我得到了在項目文件夾ariblk.ttf ...不能找到爲什麼SDL_ttf它不呈現

#include <stdio.h> 
#include <stdlib.h> 
#include <SDL.h> 
#include "SDL_ttf.h" 

int main(int argc, char *argv[]) { 

SDL_Color bgcolor,fgcolor; 
SDL_Rect rectangulo; 
SDL_Surface *screen,*ttext; 
TTF_Font *fuente; 
const char texto[14]="Hola Mundo..."; 
char msg[14]; 
SDL_Event event; 
int done = 0; 

if (SDL_Init(SDL_INIT_VIDEO) < 0) { 
printf("No se pudo iniciar SDL: %s\n",SDL_GetError()); 
return 1; 
} 

screen = SDL_SetVideoMode(640,480,24,SDL_HWSURFACE|SDL_DOUBLEBUF); 
if (screen == NULL) { 
printf("No se puede inicializar el modo gráfico: %s\n",SDL_GetError()); 
return 1; 
} 
atexit(SDL_Quit); 

if (TTF_Init() < 0) { 
printf("No se pudo iniciar SDL_ttf: %s\n",SDL_GetError()); 
return 1; 
} 
atexit(TTF_Quit); 

fuente = TTF_OpenFont("ariblk.ttf",20); 

if(fuente == NULL) 
{ 
    printf("No se pudo cargar fuente %s",TTF_GetError()); 
} 

fgcolor.r=200; 
fgcolor.g=200; 
fgcolor.b=10; 
bgcolor.r=255; 
bgcolor.g=0; 
bgcolor.b=0; 
sprintf(msg,"%s",texto); 

ttext = TTF_RenderText_Shaded(fuente,msg,fgcolor,bgcolor); 

rectangulo.y=100; 
rectangulo.x=100; 
rectangulo.w=ttext->w; 
rectangulo.h=ttext->h; 

SDL_SetColorKey(ttext,SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(ttext->format,255,0,0)); 

SDL_BlitSurface(ttext,NULL,screen,&rectangulo); 

TTF_CloseFont(fuente); 

SDL_FreeSurface(ttext); 

while(done == 0) 
     { 
     while (SDL_PollEvent(&event)) 
      { 
      if (event.type == SDL_KEYDOWN) 
      done = 1; 
      } 
     } 

    return 0; 
} 

回答

5

需要調用SDL_Flip使您的更改可以在屏幕上顯示。嘗試在源代碼中添加SDL_BlitSurface之後的SDL_Flip(screen);
希望這有助於!

+0

男士非常感謝,即時通訊新的SDL,這是一本書的例子,但如果有一些錯誤,但感謝你我修復它,謝謝=) – user1129209 2012-01-04 06:33:48

相關問題