Programmino sdl con un suono non va
Inviato: mercoledì 3 ottobre 2007, 15:45
Ho creato un programmino di prova in sdl con 2 immagini e un suono... il programma parte e le immagini si visualizzano correttametne, ma quando vado a premere il tasto per poter attivare il suono, il programma mi esce e mi dice questo:
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ...
Ho seguito le guide di http://lazyfoo.net/SDL_tutorials/index.php e provando a compilare il progetto simile che include suoni, mi da ugualmente lo stesso errore, non riesco a capire... forse devo configurare qualcosa sul compilatore??
Aspetto vostre risposte... se vi può essere utile vi do il sorgente del programma, anche se come ripeto credo sia un problema dovuto alla mancata configurazione del compilatore (uso anjuta).
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ...
Ho seguito le guide di http://lazyfoo.net/SDL_tutorials/index.php e provando a compilare il progetto simile che include suoni, mi da ugualmente lo stesso errore, non riesco a capire... forse devo configurare qualcosa sul compilatore??
Aspetto vostre risposte... se vi può essere utile vi do il sorgente del programma, anche se come ripeto credo sia un problema dovuto alla mancata configurazione del compilatore (uso anjuta).
Codice: Seleziona tutto
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_mixer.h"
#include <string>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
SDL_Surface *screen = NULL;
SDL_Surface *sfondo = NULL;
SDL_Surface *palla = NULL;
SDL_Surface *proiettile = NULL;
SDL_Surface *message = NULL;
SDL_Surface *testo = NULL;
Mix_Music *musica = NULL;
Mix_Chunk *effetto = NULL;
SDL_Event event;
TTF_Font *font = NULL;
SDL_Color textColor = { 0, 0, 0 };
//Funzione che carica le immagini sulle superfici create
SDL_Surface *load_image( std::string filename ) {
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = IMG_Load( filename.c_str() );
if( loadedImage != NULL ){
optimizedImage = SDL_DisplayFormat( loadedImage );
SDL_FreeSurface( loadedImage );
if( optimizedImage != NULL ){
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
}
}
return optimizedImage;
}
//funzione che applica le superfici allo schermo
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ){
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface( source, clip, destination, &offset );
}
//inizializza sdl
bool init(){
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ){
return false;
}
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
if( screen == NULL ){
return false;
}
if( TTF_Init() == -1 ){
return false;
}
if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ){
return false;
}
SDL_WM_SetCaption( "Monitor Music", NULL );
return true;
}
bool carica_file(){
sfondo = load_image( "background.png" );
font = TTF_OpenFont( "lazy.ttf", 72 );
palla = load_image("palla.jpg");
proiettile = load_image("proiettile.jpg");
musica = Mix_LoadMUS( "beat.wav" );
effetto = Mix_LoadWAV( "scratch.wav" );
if( sfondo == NULL ){
return false;
}
if( font == NULL ){
return false;
}
return true;
}
void scarica_file(){
//Free the surfaces
SDL_FreeSurface( sfondo );
SDL_FreeSurface( message );
//SDL_FreeSurface( up );
SDL_FreeSurface( palla );
SDL_FreeSurface( proiettile );
Mix_FreeChunk( effetto );
Mix_FreeMusic( musica );
//Close the font
TTF_CloseFont( font );
//Quit SDL_ttf
TTF_Quit();
//Quit SDL
SDL_Quit();
}
int main( int argc, char* args[] ){
bool quit = false;
if( init() == false ){
return 1;
}
//caricamento e applicazione superfici
if (carica_file() == false){
return 1;
}
testo = TTF_RenderText_Solid( font, "Ciao figlio di puttaaaaana :)", textColor );
apply_surface(0, 0, sfondo, screen);
apply_surface(50, 50, palla, screen);
//ciclo del programma
while( quit == false ){
//If there's an event to handle
if( SDL_PollEvent( &event ) ){
//If a key was pressed
if( event.type == SDL_KEYDOWN ){
apply_surface(0, 0, proiettile, screen);
//Set the proper message surface
if ( event.key.keysym.sym == SDLK_1){
/*if( Mix_PlayChannel( -1, effetto, 0 ) == -1 ){
return 1;
}*/
if( Mix_PlayMusic( musica, -1 ) == -1 ){
return 1;
}
}
}
//If the user has Xed out the window
else if( event.type == SDL_QUIT ){
quit = true;
}
}
//If a message needs to be displayed
if( message != NULL ){
//Apply the background to the screen
apply_surface( 0, 0, sfondo, screen );
//Apply the message centered on the screen
apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen );
//Null the surface pointer
message = NULL;
}
//Update the screen
if( SDL_Flip( screen ) == -1 ){
return 1;
}
}
//chiusura superfici
scarica_file();
return (0);
}