Just A Test App


SolidSnake

Member
Joined
Nov 9, 2005
Messages
188
Age
38
Location
Sao Paulo - Brazil
Website
www.solidflog.k6.com.br
Here is the code for my test app, all work without problem.. but the program just doesnt ends o.0

Code:
#include "SDL.h"
#include "SDL_ttf.h"
#include "SDL_mixer.h"

#define GP2X_BUTTON_UP              (0)
#define GP2X_BUTTON_DOWN            (4)
#define GP2X_BUTTON_LEFT            (2)
#define GP2X_BUTTON_RIGHT           (6)
#define GP2X_BUTTON_UPLEFT          (1)
#define GP2X_BUTTON_UPRIGHT         (7)
#define GP2X_BUTTON_DOWNLEFT        (3)
#define GP2X_BUTTON_DOWNRIGHT       (5)
#define GP2X_BUTTON_CLICK           (18)
#define GP2X_BUTTON_A               (12)
#define GP2X_BUTTON_B               (13)
#define GP2X_BUTTON_X               (14)
#define GP2X_BUTTON_Y               (15)
#define GP2X_BUTTON_L               (10)
#define GP2X_BUTTON_R               (11)
#define GP2X_BUTTON_START           (8)
#define GP2X_BUTTON_SELECT          (9)
#define GP2X_BUTTON_VOLUP           (16)
#define GP2X_BUTTON_VOLDOWN         (17)

typedef unsigned char u8;

SDL_Surface* screen;
TTF_Font* font;
Mix_Chunk *sound = NULL;



void drawText(SDL_Surface* screen, char* string, int x, int y, int fR, int fG, int fB)
{
	SDL_Color foregroundColor = { fR, fG, fB };
	SDL_Surface* textSurface =  TTF_RenderText_Blended(font,string, foregroundColor);
	SDL_Rect textLocation = { x, y, 0, 0 };
	SDL_BlitSurface(textSurface, NULL, screen, &textLocation);
	SDL_FreeSurface(textSurface);
}


void TestSound() {
	int channel;
	bool playit;

	do {
  SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));

  drawText(screen,"System Shock Sound Test plx :D",0,0,0,0,255);
  SDL_Flip(screen);

  sound = Mix_LoadWAV("leftright.wav");
  channel = Mix_PlayChannel(-1,sound,0);
  while(Mix_Playing(channel) != 0);

  drawText(screen, "Fim da WAV", 0, 150, 255, 255, 255);
  drawText(screen, "Para Ouvir Novamente, pressione (B)", 0, 162, 255, 0, 0);
  drawText(screen, "Para Sair, pressione (START)",0,174,255,0,0);
  SDL_Flip(screen);

  bool KeepPolling = true;
  SDL_Event event;

  while (KeepPolling)
  {
  	while ( SDL_PollEvent ( &event) )
  	{
    switch (event.type)
    {
    	case SDL_JOYBUTTONDOWN:
      
      switch (event.jbutton.button)
      {
      	case GP2X_BUTTON_B:
        playit = true;
        KeepPolling = false;
        break;
      	case GP2X_BUTTON_START:
        playit = false;
        KeepPolling = false;
        break;
      	default:
         break;
      }
    }
  	}
  }
	}
	while (playit == true);
}


int main() {
	bool quit = false;

	SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO | SDL_INIT_AUDIO);
	SDL_ShowCursor(SDL_DISABLE); // desativa o cursor
	screen = SDL_SetVideoMode( 320, 240, 32, SDL_SWSURFACE); // config de video
	SDL_JoystickOpen(0); // Inicia o joystick

	TTF_Init();

	Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 1024); // inicia o audio
	
	font = TTF_OpenFont("verdana.ttf",12);

	while(!quit) {
  SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
  drawText(screen,"Teste do Tio Solid :D",0,0,255,0,0);
  drawText(screen,"",20,30,255,133,0);
  drawText(screen,"Pressione qualquer tecla para teste de som o.0",20,42,255,133,0);
  drawText(screen,"Pressione ""Start"" Para Finalizar",20,54,255,133,0);
  
  SDL_Flip(screen);

  SDL_Event event;
  
  while (SDL_PollEvent( &event) )
  {
  	switch(event.type)
  	{
    case SDL_JOYBUTTONDOWN:
    	switch (event.jbutton.button)
    	{
      case GP2X_BUTTON_START:
      	quit = true;
      	break;
      default:
      	TestSound();
    	}
  	}

  }
	}

	SDL_FreeSurface(screen);
	Mix_FreeChunk(sound);
	Mix_CloseAudio();
	TTF_CloseFont(font);
	TTF_Quit();
    SDL_Quit();

	return 0;
}

im calling it from this bash script:
Code:
#/bin/sh
cd /mnt/sd/teste
./TesteSDL.gpe
cd /usr/gp2x
exec gp2xmenu

any idea?
 
"exec gp2xmenu" will only work if gp2xmenu is in your path - I don't think /usr/gp2x is listed. Try "exec ./gp2xmenu" or "exec /usr/gp2x/gp2xmenu" instead.
 
Back
Top