2012-01-04 2 views
1

私はコードブロックを使用していますが、既にlibraresをインストールしていて、そこにエラーはありません... 私はプロジェクトをビルドするときにエラーはなく、ウィンドウをポップアップ表示し、そのちょうど黒、との言葉「はいはいムンド...」私はプロジェクトフォルダ内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

お世話になりましたが、これは本の一例ですが、いくつかのエラーがありますが、あなたに感謝します。ありがとう=) – user1129209

関連する問題