10.07.2015 Views

[ebook]Programacion de videojuegos con SDL

[ebook]Programacion de videojuegos con SDL

[ebook]Programacion de videojuegos con SDL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

P R O G R A M A C I Ó N D E V I D E O J U E G O S C O N S D L/***************************************************************************Ejemplo4_1(C) 2003 by Alberto Garcia SerranoProgramación <strong>de</strong> vi<strong>de</strong>ojuegos <strong>con</strong> <strong>SDL</strong>***************************************************************************/#inclu<strong>de</strong> #inclu<strong>de</strong> #inclu<strong>de</strong> #inclu<strong>de</strong> "<strong>SDL</strong>_ttf.h"int main(int argc, char *argv[]) {<strong>SDL</strong>_Color bgcolor,fgcolor;<strong>SDL</strong>_Rect rectangulo;<strong>SDL</strong>_Surface *screen,*ttext;TTF_Font *fuente;<strong>con</strong>st char texto[14]="Hola Mundo...";char msg[14];<strong>SDL</strong>_Event event;int done = 0;// Inicializamos <strong>SDL</strong>if (<strong>SDL</strong>_Init(<strong>SDL</strong>_INIT_VIDEO) < 0) {printf("No se pudo iniciar <strong>SDL</strong>: %s\n",<strong>SDL</strong>_GetError());return 1;}// Inicializamos modo <strong>de</strong> vi<strong>de</strong>oscreen = <strong>SDL</strong>_SetVi<strong>de</strong>oMo<strong>de</strong>(640,480,24,<strong>SDL</strong>_HWSURFACE|<strong>SDL</strong>_DOUBLEBUF);if (screen == NULL) {printf("No se pue<strong>de</strong> inicializar el modo gráfico: \n",<strong>SDL</strong>_GetError());return 1;}atexit(<strong>SDL</strong>_Quit);// Inicializamos <strong>SDL</strong>_ttfif (TTF_Init() < 0) {printf("No se pudo iniciar <strong>SDL</strong>_ttf: %s\n",<strong>SDL</strong>_GetError());return 1;}atexit(TTF_Quit);// carga la funte <strong>de</strong> letrafuente = TTF_OpenFont("ariblk.ttf",20);// inicializa colores para el textofgcolor.r=200;fgcolor.g=200;fgcolor.b=10;bgcolor.r=255;bgcolor.g=0;bgcolor.b=0;sprintf(msg,"%s",texto);ttext = TTF_Ren<strong>de</strong>rText_Sha<strong>de</strong>d(fuente,msg,fgcolor,bgcolor);rectangulo.y=100;rectangulo.x=100;rectangulo.w=ttext->w;rectangulo.h=ttext->h;// Usamos color rojo para la transparencia <strong>de</strong>l fondo<strong>SDL</strong>_SetColorKey(ttext,<strong>SDL</strong>_SRCCOLORKEY|<strong>SDL</strong>_RLEACCEL, <strong>SDL</strong>_MapRGB(ttext->format,255,0,0));// Volcamos la superficie a la pantalla<strong>SDL</strong>_BlitSurface(ttext,NULL,screen,&rectangulo);// <strong>de</strong>struimos la fuente <strong>de</strong> letraTTF_CloseFont(fuente);64

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!