1

Im using codeblocks and i have install the librares already and there are no error there... When i build the project, the compiler says it has no errors and when i run it it just pops up a windows and inside its just black, and its suppose to appear the words "Hola Mundo..." i got ariblk.ttf in the project folder...

#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;
}
nmjohn
  • 1,432
  • 7
  • 16
user1129209
  • 19
  • 1
  • 6

1 Answers1

5

You need to call SDL_Flip to make your changes visible on the screen. Try adding SDL_Flip(screen); after SDL_BlitSurface in your source code.
Hope this helps!

another.anon.coward
  • 11,087
  • 1
  • 32
  • 38
  • Man thanks a lot, im new to SDL, and this was an example of a book, but if has some errors, but thanks to you i fix it, thanks =) – user1129209 Jan 04 '12 at 06:33