|
Main /
SDLTestMakefile.android all: i686-linux-android-gcc sdltest.c -I/opt/android/SDL-1.2.13/include -L/opt/android/SDL-1.2.13 -lSDL -lpthread -static -o sdltest Makefile.linux all: gcc sdltest.c `sdl-config --cflags --libs` -o sdltest sdltest.c
#include <SDL.h>
#include <stdio.h>
//int X_RESOLUTION = 1024;
//int Y_RESOLUTION = 768;
// My avd is WGVA (800x480)
int X_RESOLUTION = 480;
int Y_RESOLUTION = 800;
int BPP = 24;
int fullscreen = 1;
const int DELAY = 1;
int quit = 0;
SDL_Surface *surface;
SDL_Surface *piDefender = NULL;
SDL_Surface *piStargate = NULL;
int game_selected = 0; // defender = 0, stargate = 1
void run_program() {
// if (game_selected) {
// system("mame -skip_gameinfo stargate");
//}
//else {
// system("mame -skip_gameinfo defender");
//}
}
SDL_Surface *loadimage(const char *filename) {
SDL_Surface *image;
SDL_Surface *temp;
temp = SDL_LoadBMP(filename);
if (temp == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return NULL;
}
image = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
return image;
}
void Quit( int returnCode )
{
/* clean up the window */
SDL_Quit( );
/* and exit appropriately */
//exit( returnCode );
}
void init(int argc, char **argv) {
int videoFlags;
/* initialize SDL */
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
fprintf( stderr, "SDL initialization failed: %s\n",
SDL_GetError( ) );
Quit( 1 );
}
//const SDL_VideoInfo *vid = SDL_GetVideoInfo();
//X_RESOLUTION = vid->current_w;
//Y_RESOLUTION = vid->current_h;
/* get a SDL surface */
//surface = SDL_SetVideoMode(X_RESOLUTION, Y_RESOLUTION, 0, SDL_DOUBLEBUF | SDL_ANYFORMAT | SDL_FULLSCREEN);
surface = SDL_SetVideoMode(X_RESOLUTION, Y_RESOLUTION, 0, SDL_DOUBLEBUF | SDL_ANYFORMAT );
/* Verify there is a surface */
if ( !surface )
{
fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
Quit( 1 );
}
SDL_ShowCursor(SDL_DISABLE);
/*
//toggle_fullscreen();
SDL_FreeSurface(surface);
SDL_Surface* temp;
if (!fullscreen) {
temp = SDL_SetVideoMode(X_RESOLUTION, Y_RESOLUTION, 0, SDL_DOUBLEBUF | SDL_ANYFORMAT | SDL_FULLSCREEN);
}
else {
temp = SDL_SetVideoMode(X_RESOLUTION, Y_RESOLUTION, 0, SDL_DOUBLEBUF | SDL_ANYFORMAT);
}
surface = temp;
fullscreen = !fullscreen;
*/
}
/* function to handle key press events */
void handleKeyPress( SDL_keysym *keysym )
{
switch ( keysym->sym )
{
case SDLK_ESCAPE:
/* ESC key was pressed */
quit = 1;
break;
case SDLK_q:
/* ESC key was pressed */
quit = 1;
break;
case SDLK_l:
if (game_selected != 0) {
game_selected = 0;
}
break;
case SDLK_k:
if (game_selected != 1) {
game_selected = 1;
}
break;
default:
break;
}
return;
}
void check_input() {
SDL_Event event;
while ( SDL_PollEvent( &event ) )
{
switch( event.type )
{
case SDL_KEYDOWN:
/* handle key presses */
handleKeyPress( &event.key.keysym );
break;
case SDL_QUIT:
/* handle quit requests */
quit = 1;
break;
default:
break;
}
}
}
void draw_scene() {
SDL_Rect dest;
SDL_Rect src;
SDL_Surface *image;
switch(game_selected) {
case 0:
image = piDefender;
break;
default:
image = piStargate;
break;
}
SDL_BlitSurface(image, NULL, surface, NULL);
SDL_Flip(surface);
}
void main_loop() {
while(!quit) {
if (DELAY) {
SDL_Delay(5);
}
check_input();
draw_scene();
}
}
int main(int argc, char **argv) {
init(argc,argv);
// Load images
//piDefender = loadimage("/data/misc/data/defender.bmp");
//piStargate = loadimage("/data/misc/data/stargate.bmp");
piDefender = loadimage("data/defender.bmp");
piStargate = loadimage("data/stargate.bmp");
// Main Loop
main_loop();
// It's embarassing and ridiculous, but SDL_Quit takes 3 seconds to run on
// Ubuntu 10.04, so I'm avoiding SDL_Quit by toggling fullscreen and harshly
// exiting the app.
//SDL_Quit();
return 0;
}
readme.txt sdltest This program runs in Android. It displays two images. Press the l and k keys to choose the image to display. The Q key is for quit, which is inappropriate for android, and crashes the system. Currently it is configured for the emulator mode with a 480x800 display. Process to run it on Android: make -f Makefile.linux ./sdltest # Press l, k to change images, and q to quit. Process to run it on Linux: emulator -avd myavd & make -f Makefile.android adb push sdltest /data/misc/ adb shell mkdir /data/misc/data/ adb push data/defender.bmp /data/misc/data/ adb push data/stargate.bmp /data/misc/data/ adb shell # cd /data/misc # ./sdltest Major problems: * Hitting the menu button doesn't return to the menu, the app remains. * Quitting by pressing the Q key seems to basically crash the gui system. * It is not in a java wrapper, so it is breaking some of the rules for sure. * I can't run it on my device because I don't have root access. * The app starts and overrides the locked screen! Todo: * Configure the application with a java wrapper. ** Run it without crashing on the emulator ** Run it on my phone. |