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/*****************************************Ejemplo3_4(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> <strong>SDL</strong>_Surface* superficie;<strong>SDL</strong>_Event event;<strong>SDL</strong>_AudioSpec* <strong>de</strong>seado;<strong>SDL</strong>_AudioSpec* obtenido;int done;// <strong>de</strong>claración <strong>de</strong> la función <strong>de</strong> retrollamadavoid retrollamada(void* userdata,Uint8* buffer,int len);int main(int argc, char* argv[]) {// Inicializamos <strong>SDL</strong>if (<strong>SDL</strong>_Init(<strong>SDL</strong>_INIT_VIDEO|<strong>SDL</strong>_INIT_AUDIO) < 0) {printf("No se pudo inicializar <strong>SDL</strong>.\n");exit(1);}// Inicializamos modo <strong>de</strong> vi<strong>de</strong>o// (en Windows es necesario para que funcione el audio)if ( (superficie = <strong>SDL</strong>_SetVi<strong>de</strong>oMo<strong>de</strong>(640,480,0,<strong>SDL</strong>_ANYFORMAT)) == NULL) {printf("No se pudo inicializar la ventana.\n");exit(1);}// Alojamos espacio para almacenar las estructuras<strong>de</strong>seado=new <strong>SDL</strong>_AudioSpec;obtenido=new <strong>SDL</strong>_AudioSpec;// especificaciones <strong>de</strong>seadas<strong>de</strong>seado->freq=11025;<strong>de</strong>seado->format=AUDIO_S16SYS;<strong>de</strong>seado->channels=1;<strong>de</strong>seado->samples=4096;<strong>de</strong>seado->callback=retrollamada;<strong>de</strong>seado->userdata=NULL;// abrimos el dispositivo <strong>de</strong> audioif(<strong>SDL</strong>_OpenAudio(<strong>de</strong>seado,obtenido)

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

Saved successfully!

Ooh no, something went wrong!