Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
authorSam Lantinga <slouken@libsdl.org>
Thu, 06 Jan 2011 16:11:21 -0800
changeset 49646c645018741e
parent 4963 604077962776
child 4965 91d0085b7560
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Android.mk
Makefile.android
README.android
android/config.cfg.example
android/project/AndroidManifest.xml
android/project/build.properties
android/project/build.xml
android/project/default.properties
android/project/jni/Android.mk
android/project/jni/android-support.cpp
android/project/jni/lesson05.c
android/project/local.properties
android/project/res/drawable-hdpi/icon.png
android/project/res/drawable-ldpi/icon.png
android/project/res/drawable-mdpi/icon.png
android/project/res/layout/main.xml
android/project/res/values/strings.xml
android/project/src/org/libsdl/app/SDLActivity.java
include/SDL_config_android.h
src/SDL_android.cpp
src/main/android/SDL_android_main.cpp
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Android.mk	Thu Jan 06 16:11:21 2011 -0800
     1.3 @@ -0,0 +1,41 @@
     1.4 +LOCAL_PATH := $(call my-dir)
     1.5 +
     1.6 +###########################
     1.7 +#
     1.8 +# SDL shared library
     1.9 +#
    1.10 +###########################
    1.11 +
    1.12 +include $(CLEAR_VARS)
    1.13 +
    1.14 +LOCAL_MODULE := SDL
    1.15 +
    1.16 +LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
    1.17 +
    1.18 +LOCAL_SRC_FILES := src/SDL_android.cpp \
    1.19 +	$(subst $(LOCAL_PATH)/,, \
    1.20 +	$(wildcard $(LOCAL_PATH)/src/*.c) \
    1.21 +	$(wildcard $(LOCAL_PATH)/src/audio/*.c) \
    1.22 +	$(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \
    1.23 +	$(wildcard $(LOCAL_PATH)/src/events/*.c) \
    1.24 +	$(wildcard $(LOCAL_PATH)/src/file/*.c) \
    1.25 +	$(wildcard $(LOCAL_PATH)/src/joystick/*.c) \
    1.26 +	$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \
    1.27 +	$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \
    1.28 +	$(wildcard $(LOCAL_PATH)/src/thread/*.c) \
    1.29 +	$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
    1.30 +	$(wildcard $(LOCAL_PATH)/src/video/*.c) \
    1.31 +	$(wildcard $(LOCAL_PATH)/src/power/*.c) \
    1.32 +	$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
    1.33 +	$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \
    1.34 +	$(wildcard $(LOCAL_PATH)/src/video/android/*.c) \
    1.35 +	$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \
    1.36 +	$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \
    1.37 +	$(wildcard $(LOCAL_PATH)/src/atomic/dummy/*.c) \
    1.38 +	$(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \
    1.39 +	$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
    1.40 +	$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c))
    1.41 +
    1.42 +LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog
    1.43 +
    1.44 +include $(BUILD_SHARED_LIBRARY)
     2.1 --- a/Makefile.android	Wed Jan 05 00:09:19 2011 -0800
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,58 +0,0 @@
     2.4 -# Makefile to build the SDL library
     2.5 -
     2.6 -include ./android/config.cfg #get ANDROID_NDK, ANDROID_NDK_HOST
     2.7 -
     2.8 -# For NDK R4
     2.9 -TOOLS_PATH=$(ANDROID_NDK)/build/prebuilt/$(ANDROID_NDK_HOST)/arm-eabi-4.2.1/bin
    2.10 -ANDROID_INCLUDES = -I$(ANDROID_NDK)/build/platforms/android-4/arch-arm/usr/include 
    2.11 -
    2.12 -# For NDK R5
    2.13 -#TOOLS_PATH=$(ANDROID_NDK)/toolchains/arm-eabi-4.4.0/prebuilt/$(ANDROID_NDK_HOST)/bin
    2.14 -#ANDROID_INCLUDES = -I$(ANDROID_NDK)/platforms/android-4/arch-arm/usr/include 
    2.15 -
    2.16 -INCLUDE = -I./include
    2.17 -CFLAGS  = -g -O2 -fno-short-enums $(INCLUDE) $(ANDROID_INCLUDES) -DANDROID -DANDROID_NDK -static
    2.18 -
    2.19 -AR	= $(TOOLS_PATH)/arm-eabi-ar
    2.20 -RANLIB	= $(TOOLS_PATH)/arm-eabi-ranlib
    2.21 -CC = $(TOOLS_PATH)/arm-eabi-gcc
    2.22 -
    2.23 -
    2.24 -CONFIG_H = include/SDL_config.h
    2.25 -TARGET  = libSDL.a
    2.26 -SOURCES = \
    2.27 -	src/*.c \
    2.28 -	src/audio/*.c \
    2.29 -	src/cpuinfo/*.c \
    2.30 -	src/events/*.c \
    2.31 -	src/file/*.c \
    2.32 -	src/joystick/*.c \
    2.33 -	src/haptic/*.c \
    2.34 -	src/stdlib/*.c \
    2.35 -	src/thread/*.c \
    2.36 -	src/timer/*.c \
    2.37 -	src/video/*.c \
    2.38 -	src/power/*.c \
    2.39 -	src/audio/android/*.c \
    2.40 -	src/audio/dummy/*.c \
    2.41 -	src/video/android/*.c \
    2.42 -	src/joystick/android/*.c \
    2.43 -	src/haptic/dummy/*.c \
    2.44 -	src/atomic/dummy/*.c \
    2.45 -	src/thread/pthread/*.c \
    2.46 -	src/timer/unix/*.c \
    2.47 -	src/loadso/dummy/*.c \
    2.48 -
    2.49 -OBJECTS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
    2.50 -
    2.51 -all: $(TARGET)
    2.52 -
    2.53 -$(TARGET): $(CONFIG_H) $(OBJECTS)
    2.54 -	$(AR) crv $@ $^
    2.55 -	$(RANLIB) $@
    2.56 -
    2.57 -$(CONFIG_H):
    2.58 -	cp $(CONFIG_H).default $(CONFIG_H)
    2.59 -
    2.60 -clean:
    2.61 -	rm -f $(TARGET) $(OBJECTS)
     3.1 --- a/README.android	Wed Jan 05 00:09:19 2011 -0800
     3.2 +++ b/README.android	Thu Jan 06 16:11:21 2011 -0800
     3.3 @@ -2,7 +2,8 @@
     3.4  Simple DirectMedia Layer for Android
     3.5  ================================================================================
     3.6  
     3.7 -Requirements: Android NDK r4 or later
     3.8 +Requirements: Android SDK and Android NDK r4 or later
     3.9 +http://developer.android.com/
    3.10  
    3.11  ================================================================================
    3.12   How the port works
    3.13 @@ -16,26 +17,44 @@
    3.14  - This eventually produces a standard Android .apk package
    3.15  
    3.16  
    3.17 -
    3.18 -
    3.19 -
    3.20 -
    3.21  ================================================================================
    3.22   Building an app
    3.23  ================================================================================
    3.24  
    3.25  Instructions:
    3.26 -1. Edit android/config.cfg to point to the location of the NDK
    3.27 -2. Run 'make -f Makefile.android'. If all goes well, libsdl.a should be created
    3.28 -3. Place your application source files in android/project/jni
    3.29 -4. Edit the Android.mk to include your source files
    3.30 +1. Copy the android-project directory wherever you want your Android project to go
    3.31 +2. Move this SDL directory into the <project>/jni directory
    3.32 +3. Place your application source files in the <project>/jni/src directory
    3.33 +4. Edit <project>/jni/src/Android.mk to include your source files
    3.34  5. Run 'ndk-build' (a script provided by the NDK). This compiles the C source
    3.35 -6. Edit project/local.properties to point to the SDK directory
    3.36 -6. Run 'ant debug' in android/project. This compiles the .java and eventually 
    3.37 -creates a .apk with the C source embedded
    3.38 -7. 'ant install' will push the apk to the device or emulator (if connected)
    3.39  
    3.40 +If you want to use the Eclipse IDE, skip to the Eclipse section below.
    3.41  
    3.42 +6. Edit <project>/local.properties to point to the Android SDK directory
    3.43 +7. Run 'ant debug' in android/project. This compiles the .java and eventually 
    3.44 +creates a .apk with the native code embedded
    3.45 +8. 'ant install' will push the apk to the device or emulator (if connected)
    3.46 +
    3.47 +
    3.48 +================================================================================
    3.49 + Using Eclipse
    3.50 +================================================================================
    3.51 +
    3.52 +NEED CONTENT
    3.53 +
    3.54 +
    3.55 +================================================================================
    3.56 + Loading files
    3.57 +================================================================================
    3.58 +
    3.59 +NEED CONTENT
    3.60 +
    3.61 +
    3.62 +================================================================================
    3.63 + Troubleshooting
    3.64 +================================================================================
    3.65 +
    3.66 +NEED CONTENT
    3.67  
    3.68  
    3.69  ================================================================================
     4.1 --- a/android/config.cfg.example	Wed Jan 05 00:09:19 2011 -0800
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,8 +0,0 @@
     4.4 -# This file sets up paths needed to find the NDK build tools.
     4.5 -# Edit it appropriately for your configuration and save it as "config.cfg".
     4.6 -
     4.7 -# This should be the full path to the Android NDK
     4.8 -ANDROID_NDK := /Users/hercules/eclipse/android-ndk-r5
     4.9 -
    4.10 -# This should be "linux-x86" for linux, "darwin-x86" for mac
    4.11 -ANDROID_NDK_HOST := darwin-x86
     5.1 --- a/android/project/AndroidManifest.xml	Wed Jan 05 00:09:19 2011 -0800
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,15 +0,0 @@
     5.4 -<?xml version="1.0" encoding="utf-8"?>
     5.5 -<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     5.6 -      package="org.libsdl.app"
     5.7 -      android:versionCode="1"
     5.8 -      android:versionName="1.0">
     5.9 -    <application android:label="@string/app_name" android:icon="@drawable/icon">
    5.10 -        <activity android:name="SDLActivity"
    5.11 -                  android:label="@string/app_name">
    5.12 -            <intent-filter>
    5.13 -                <action android:name="android.intent.action.MAIN" />
    5.14 -                <category android:name="android.intent.category.LAUNCHER" />
    5.15 -            </intent-filter>
    5.16 -        </activity>
    5.17 -    </application>
    5.18 -</manifest> 
     6.1 --- a/android/project/build.properties	Wed Jan 05 00:09:19 2011 -0800
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,17 +0,0 @@
     6.4 -# This file is used to override default values used by the Ant build system.
     6.5 -# 
     6.6 -# This file must be checked in Version Control Systems, as it is
     6.7 -# integral to the build system of your project.
     6.8 -
     6.9 -# This file is only used by the Ant script.
    6.10 -
    6.11 -# You can use this to override default values such as
    6.12 -#  'source.dir' for the location of your java source folder and
    6.13 -#  'out.dir' for the location of your output folder.
    6.14 -
    6.15 -# You can also use it define how the release builds are signed by declaring
    6.16 -# the following properties:
    6.17 -#  'key.store' for the location of your keystore and
    6.18 -#  'key.alias' for the name of the key to use.
    6.19 -# The password will be asked during the build when you use the 'release' target.
    6.20 -
     7.1 --- a/android/project/build.xml	Wed Jan 05 00:09:19 2011 -0800
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,67 +0,0 @@
     7.4 -<?xml version="1.0" encoding="UTF-8"?>
     7.5 -<project name="SDLApp" default="help">
     7.6 -
     7.7 -    <!-- The local.properties file is created and updated by the 'android' tool.
     7.8 -         It contains the path to the SDK. It should *NOT* be checked in in Version
     7.9 -         Control Systems. -->
    7.10 -    <property file="local.properties" />
    7.11 -
    7.12 -    <!-- The build.properties file can be created by you and is never touched
    7.13 -         by the 'android' tool. This is the place to change some of the default property values
    7.14 -         used by the Ant rules.
    7.15 -         Here are some properties you may want to change/update:
    7.16 -
    7.17 -         application.package
    7.18 -             the name of your application package as defined in the manifest. Used by the
    7.19 -             'uninstall' rule.
    7.20 -         source.dir
    7.21 -             the name of the source directory. Default is 'src'.
    7.22 -         out.dir
    7.23 -             the name of the output directory. Default is 'bin'.
    7.24 -
    7.25 -         Properties related to the SDK location or the project target should be updated
    7.26 -          using the 'android' tool with the 'update' action.
    7.27 -
    7.28 -         This file is an integral part of the build system for your application and
    7.29 -         should be checked in in Version Control Systems.
    7.30 -
    7.31 -         -->
    7.32 -    <property file="build.properties" />
    7.33 -
    7.34 -    <!-- The default.properties file is created and updated by the 'android' tool, as well
    7.35 -         as ADT.
    7.36 -         This file is an integral part of the build system for your application and
    7.37 -         should be checked in in Version Control Systems. -->
    7.38 -    <property file="default.properties" />
    7.39 -
    7.40 -    <!-- Custom Android task to deal with the project target, and import the proper rules.
    7.41 -         This requires ant 1.6.0 or above. -->
    7.42 -    <path id="android.antlibs">
    7.43 -        <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
    7.44 -        <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
    7.45 -        <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
    7.46 -        <pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
    7.47 -        <pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
    7.48 -    </path>
    7.49 -
    7.50 -    <taskdef name="setup"
    7.51 -        classname="com.android.ant.SetupTask"
    7.52 -        classpathref="android.antlibs" />
    7.53 -
    7.54 -    <!-- Execute the Android Setup task that will setup some properties specific to the target,
    7.55 -         and import the build rules files.
    7.56 -
    7.57 -         The rules file is imported from
    7.58 -            <SDK>/platforms/<target_platform>/templates/android_rules.xml
    7.59 -
    7.60 -         To customize some build steps for your project:
    7.61 -         - copy the content of the main node <project> from android_rules.xml
    7.62 -         - paste it in this build.xml below the <setup /> task.
    7.63 -         - disable the import by changing the setup task below to <setup import="false" />
    7.64 -
    7.65 -         This will ensure that the properties are setup correctly but that your customized
    7.66 -         build steps are used.
    7.67 -    -->
    7.68 -    <setup />
    7.69 -
    7.70 -</project>
     8.1 --- a/android/project/default.properties	Wed Jan 05 00:09:19 2011 -0800
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,11 +0,0 @@
     8.4 -# This file is automatically generated by Android Tools.
     8.5 -# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
     8.6 -# 
     8.7 -# This file must be checked in Version Control Systems.
     8.8 -# 
     8.9 -# To customize properties used by the Ant build system use,
    8.10 -# "build.properties", and override values to adapt the script to your
    8.11 -# project structure.
    8.12 -
    8.13 -# Project target.
    8.14 -target=android-4
     9.1 --- a/android/project/jni/Android.mk	Wed Jan 05 00:09:19 2011 -0800
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,18 +0,0 @@
     9.4 -LOCAL_PATH := $(call my-dir)
     9.5 -
     9.6 -include $(CLEAR_VARS)
     9.7 -
     9.8 -LOCAL_MODULE := sdlapp
     9.9 -SDL := ../../../
    9.10 -
    9.11 -LOCAL_CFLAGS := -DANDROID_NDK \
    9.12 -                -DDISABLE_IMPORTGL \
    9.13 -                -I$(SDL)/include
    9.14 -
    9.15 -LOCAL_SRC_FILES := \
    9.16 -    android-support.cpp \
    9.17 -    lesson05.c \
    9.18 -
    9.19 -LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog -lSDL -lgcc -L$(SDL)
    9.20 -
    9.21 -include $(BUILD_SHARED_LIBRARY)
    10.1 --- a/android/project/jni/android-support.cpp	Wed Jan 05 00:09:19 2011 -0800
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,245 +0,0 @@
    10.4 -/*******************************************************************************
    10.5 - This file links the Java side of Android with libsdl
    10.6 -*******************************************************************************/
    10.7 -#include <jni.h>
    10.8 -#include <sys/time.h>
    10.9 -#include <time.h>
   10.10 -#include <android/log.h>
   10.11 -#include <stdint.h>
   10.12 -#include <stdio.h>
   10.13 -#include <stdlib.h>
   10.14 -#include <math.h>
   10.15 -#include <pthread.h>
   10.16 -
   10.17 -#define DEBUG
   10.18 -
   10.19 -
   10.20 -/*******************************************************************************
   10.21 -                               Globals
   10.22 -*******************************************************************************/
   10.23 -static long _getTime(void){
   10.24 -	struct timeval  now;
   10.25 -	gettimeofday(&now, NULL);
   10.26 -	return (long)(now.tv_sec*1000 + now.tv_usec/1000);
   10.27 -}
   10.28 -
   10.29 -JNIEnv* mEnv = NULL;
   10.30 -JNIEnv* mAudioThreadEnv = NULL; //See the note below for why this is necessary
   10.31 -JavaVM* mVM = NULL;
   10.32 -
   10.33 -//Main activity
   10.34 -jclass mActivityInstance;
   10.35 -
   10.36 -//method signatures
   10.37 -jmethodID midCreateGLContext;
   10.38 -jmethodID midFlipBuffers;
   10.39 -jmethodID midEnableFeature;
   10.40 -jmethodID midUpdateAudio;
   10.41 -
   10.42 -extern "C" int SDL_main(int argc, char *argv[]);
   10.43 -extern "C" int Android_OnKeyDown(int keycode);
   10.44 -extern "C" int Android_OnKeyUp(int keycode);
   10.45 -extern "C" void Android_SetScreenResolution(int width, int height);
   10.46 -extern "C" void Android_OnResize(int width, int height, int format);
   10.47 -extern "C" int SDL_SendQuit();
   10.48 -extern "C" void Android_EnableFeature(int featureid, bool enabled);
   10.49 -
   10.50 -//If we're not the active app, don't try to render
   10.51 -bool bRenderingEnabled = false;
   10.52 -
   10.53 -//Feature IDs
   10.54 -static const int FEATURE_AUDIO = 1;
   10.55 -static const int FEATURE_ACCEL = 2;
   10.56 -
   10.57 -//Accelerometer data storage
   10.58 -float fLastAccelerometer[3];
   10.59 -
   10.60 -
   10.61 -/*******************************************************************************
   10.62 -                 Functions called by JNI
   10.63 -*******************************************************************************/	
   10.64 -
   10.65 -//Library init
   10.66 -extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){
   10.67 -
   10.68 -    JNIEnv* env = NULL;
   10.69 -    jint result = -1;
   10.70 -
   10.71 -    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
   10.72 -        return result;
   10.73 -    }
   10.74 -
   10.75 -    mEnv = env;
   10.76 -
   10.77 -    __android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: OnLoad");
   10.78 -
   10.79 -    jclass cls = mEnv->FindClass ("org/libsdl/app/SDLActivity"); 
   10.80 -    mActivityInstance = cls;
   10.81 -    midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
   10.82 -    midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
   10.83 -    midEnableFeature = mEnv->GetStaticMethodID(cls,"enableFeature","(II)V");
   10.84 -    midUpdateAudio = mEnv->GetStaticMethodID(cls,"updateAudio","([B)V");
   10.85 -
   10.86 -    if(!midCreateGLContext || !midFlipBuffers || !midEnableFeature ||
   10.87 -        !midUpdateAudio){
   10.88 -        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n");
   10.89 -    }else{
   10.90 -#ifdef DEBUG
   10.91 -        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Good mids\n");
   10.92 -#endif
   10.93 -    }
   10.94 -    
   10.95 -    return JNI_VERSION_1_4;
   10.96 -}
   10.97 -
   10.98 -//Start up the SDL app
   10.99 -extern "C" void Java_org_libsdl_app_SDLActivity_nativeInit( JNIEnv* env, 
  10.100 -                                                                jobject obj ){ 
  10.101 -                                                                   
  10.102 -	__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init");
  10.103 -
  10.104 -	mEnv = env;
  10.105 -	bRenderingEnabled = true;
  10.106 -
  10.107 -	Android_EnableFeature(FEATURE_ACCEL, true);
  10.108 -
  10.109 -    char *argv[2];
  10.110 -    argv[0] = strdup("SDL_app");
  10.111 -    argv[1] = NULL;
  10.112 -    SDL_main(1, argv);
  10.113 -}
  10.114 -
  10.115 -//Keydown
  10.116 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown(JNIEnv* env, 
  10.117 -               jobject obj, jint keycode){
  10.118 -    
  10.119 -    int r = Android_OnKeyDown(keycode);
  10.120 -#ifdef DEBUG
  10.121 -    __android_log_print(ANDROID_LOG_INFO, "SDL", 
  10.122 -                        "SDL: native key down %d, %d\n", keycode, r);
  10.123 -#endif
  10.124 -                        
  10.125 -}
  10.126 -
  10.127 -//Keyup
  10.128 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp(JNIEnv* env, 
  10.129 -               jobject obj, jint keycode){
  10.130 -    
  10.131 -    int r = Android_OnKeyUp(keycode);
  10.132 -#ifdef DEBUG
  10.133 -    __android_log_print(ANDROID_LOG_INFO, "SDL", 
  10.134 -                        "SDL: native key up %d, %d\n", keycode, r);
  10.135 -#endif
  10.136 -                        
  10.137 -}
  10.138 -
  10.139 -//Touch
  10.140 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(JNIEnv* env, 
  10.141 -               jobject obj, jint action, jfloat x, jfloat y, jfloat p){
  10.142 -
  10.143 -#ifdef DEBUG
  10.144 -    __android_log_print(ANDROID_LOG_INFO, "SDL", 
  10.145 -                        "SDL: native touch event %d @ %f/%f, pressure %f\n", 
  10.146 -                        action, x, y, p);
  10.147 -#endif
  10.148 -
  10.149 -    //TODO: Pass this off to the SDL multitouch stuff
  10.150 -                        
  10.151 -}
  10.152 -
  10.153 -//Quit
  10.154 -extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit( JNIEnv*  env, 
  10.155 -                                                                jobject obj ){    
  10.156 -
  10.157 -    //Stop rendering as we're no longer in the foreground
  10.158 -	bRenderingEnabled = false;
  10.159 -
  10.160 -    //Inject a SDL_QUIT event
  10.161 -    int r = SDL_SendQuit();
  10.162 -
  10.163 -    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native quit %d", r);        
  10.164 -}
  10.165 -
  10.166 -//Screen size
  10.167 -extern "C" void Java_org_libsdl_app_SDLActivity_nativeSetScreenSize(
  10.168 -                JNIEnv*  env, jobject obj, jint width, jint height){
  10.169 -
  10.170 -    __android_log_print(ANDROID_LOG_INFO, "SDL", 
  10.171 -                        "SDL: Set screen size on init: %d/%d\n", width, height);
  10.172 -    Android_SetScreenResolution(width, height);
  10.173 -                        
  10.174 -}
  10.175 -
  10.176 -//Resize
  10.177 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize(
  10.178 -                                        JNIEnv*  env, jobject obj, jint width, 
  10.179 -                                        jint height, jint format){
  10.180 -    Android_OnResize(width, height, format);
  10.181 -}
  10.182 -
  10.183 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
  10.184 -                                        JNIEnv*  env, jobject obj,
  10.185 -                                        jfloat x, jfloat y, jfloat z){
  10.186 -    fLastAccelerometer[0] = x;
  10.187 -    fLastAccelerometer[1] = y;
  10.188 -    fLastAccelerometer[2] = z;   
  10.189 -}
  10.190 -
  10.191 -
  10.192 -
  10.193 -/*******************************************************************************
  10.194 -             Functions called by SDL into Java
  10.195 -*******************************************************************************/
  10.196 -extern "C" void Android_CreateContext(){
  10.197 -	__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n");
  10.198 -
  10.199 -	bRenderingEnabled = true;
  10.200 -
  10.201 -    mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext ); 
  10.202 -}
  10.203 -
  10.204 -extern "C" void Android_Render(){
  10.205 -
  10.206 -    if(!bRenderingEnabled){
  10.207 -        return;
  10.208 -    }
  10.209 -
  10.210 -    //When we get here, we've accumulated a full frame    
  10.211 -    mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers ); 
  10.212 -}
  10.213 -
  10.214 -extern "C" void Android_EnableFeature(int featureid, bool enabled){
  10.215 -
  10.216 -    mEnv->CallStaticVoidMethod(mActivityInstance, midEnableFeature, 
  10.217 -                                featureid, (int)enabled); 
  10.218 -}
  10.219 -
  10.220 -extern "C" void Android_UpdateAudioBuffer(unsigned char *buf, int len){
  10.221 -
  10.222 -    //Annoyingly we can't just call into Java from any thread. Because the audio
  10.223 -    //callback is dispatched from the SDL audio thread (that wasn't made from
  10.224 -    //java, we have to do some magic here to let the JVM know about the thread.
  10.225 -    //Because everything it touches on the Java side is static anyway, it's 
  10.226 -    //not a big deal, just annoying.
  10.227 -    if(!mAudioThreadEnv){
  10.228 -        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Need to set up audio thread env\n");
  10.229 -
  10.230 -        mVM->AttachCurrentThread(&mAudioThreadEnv, NULL);
  10.231 -
  10.232 -        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: ok\n");
  10.233 -    }
  10.234 -    
  10.235 -    jbyteArray arr = mAudioThreadEnv->NewByteArray(len);
  10.236 -
  10.237 -    //blah. We probably should rework this so we avoid the copy. 
  10.238 -    mAudioThreadEnv->SetByteArrayRegion(arr, 0, len, (jbyte *)buf);
  10.239 -    
  10.240 -    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: copied\n");
  10.241 -
  10.242 -    mAudioThreadEnv->CallStaticVoidMethod(  mActivityInstance, 
  10.243 -                                            midUpdateAudio, arr );
  10.244 -
  10.245 -    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: invoked\n");
  10.246 -    
  10.247 -}
  10.248 -
    11.1 --- a/android/project/jni/lesson05.c	Wed Jan 05 00:09:19 2011 -0800
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,574 +0,0 @@
    11.4 -/*
    11.5 - * This code was created by Jeff Molofee '99 
    11.6 - * (ported to Linux/SDL by Ti Leggett '01)
    11.7 - *
    11.8 - * If you've found this code useful, please let me know.
    11.9 - *
   11.10 - * Visit Jeff at http://nehe.gamedev.net/
   11.11 - * 
   11.12 - * or for port-specific comments, questions, bugreports etc. 
   11.13 - * email to leggett@eecs.tulane.edu
   11.14 - */
   11.15 - 
   11.16 -#include <stdio.h>
   11.17 -#include <stdlib.h>
   11.18 -#include <math.h>
   11.19 -
   11.20 -#include <signal.h>
   11.21 -
   11.22 -#include <android/log.h>
   11.23 -
   11.24 -
   11.25 -#ifdef ANDROID
   11.26 -#include <GLES/gl.h>
   11.27 -#else
   11.28 -#include <GL/gl.h>
   11.29 -#include <GL/glu.h>
   11.30 -#endif
   11.31 -#include "SDL.h"
   11.32 -
   11.33 -/* screen width, height, and bit depth */
   11.34 -#define SCREEN_WIDTH  320
   11.35 -#define SCREEN_HEIGHT 430
   11.36 -#define SCREEN_BPP     16
   11.37 -
   11.38 -/* Define our booleans */
   11.39 -#define TRUE  1
   11.40 -#define FALSE 0
   11.41 -
   11.42 -/* This is our SDL surface */
   11.43 -SDL_Surface *surface;
   11.44 -
   11.45 -int rotation = 0;
   11.46 -
   11.47 -
   11.48 -/**************************************
   11.49 -	gluperspective implementation
   11.50 -**************************************/
   11.51 -void gluPerspective(double fovy, double aspect, double zNear, double zFar){
   11.52 -	glMatrixMode(GL_PROJECTION);
   11.53 -	glLoadIdentity();
   11.54 -	double xmin, xmax, ymin, ymax;
   11.55 -	ymax = zNear * tan(fovy * M_PI / 360.0);
   11.56 -	ymin = -ymax;
   11.57 -	xmin = ymin * aspect;
   11.58 -	xmax = ymax * aspect;
   11.59 -	glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
   11.60 -}
   11.61 -
   11.62 -
   11.63 -/**************************************
   11.64 -	  glulookat implementation
   11.65 -**************************************/
   11.66 -void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
   11.67 -          GLfloat centerx, GLfloat centery, GLfloat centerz,
   11.68 -          GLfloat upx, GLfloat upy, GLfloat upz)
   11.69 -{
   11.70 -    GLfloat m[16];
   11.71 -    GLfloat x[3], y[3], z[3];
   11.72 -    GLfloat mag;
   11.73 -    
   11.74 -    /* Make rotation matrix */
   11.75 -    
   11.76 -    /* Z vector */
   11.77 -    z[0] = eyex - centerx;
   11.78 -    z[1] = eyey - centery;
   11.79 -    z[2] = eyez - centerz;
   11.80 -    mag = sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
   11.81 -    if (mag) {          /* mpichler, 19950515 */
   11.82 -        z[0] /= mag;
   11.83 -        z[1] /= mag;
   11.84 -        z[2] /= mag;
   11.85 -    }
   11.86 -    
   11.87 -    /* Y vector */
   11.88 -    y[0] = upx;
   11.89 -    y[1] = upy;
   11.90 -    y[2] = upz;
   11.91 -    
   11.92 -    /* X vector = Y cross Z */
   11.93 -    x[0] = y[1] * z[2] - y[2] * z[1];
   11.94 -    x[1] = -y[0] * z[2] + y[2] * z[0];
   11.95 -    x[2] = y[0] * z[1] - y[1] * z[0];
   11.96 -    
   11.97 -    /* Recompute Y = Z cross X */
   11.98 -    y[0] = z[1] * x[2] - z[2] * x[1];
   11.99 -    y[1] = -z[0] * x[2] + z[2] * x[0];
  11.100 -    y[2] = z[0] * x[1] - z[1] * x[0];
  11.101 -    
  11.102 -    /* mpichler, 19950515 */
  11.103 -    /* cross product gives area of parallelogram, which is < 1.0 for
  11.104 -     * non-perpendicular unit-length vectors; so normalize x, y here
  11.105 -     */
  11.106 -    
  11.107 -    mag = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
  11.108 -    if (mag) {
  11.109 -        x[0] /= mag;
  11.110 -        x[1] /= mag;
  11.111 -        x[2] /= mag;
  11.112 -    }
  11.113 -    
  11.114 -    mag = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
  11.115 -    if (mag) {
  11.116 -        y[0] /= mag;
  11.117 -        y[1] /= mag;
  11.118 -        y[2] /= mag;
  11.119 -    }
  11.120 -    
  11.121 -#define M(row,col)  m[col*4+row]
  11.122 -    M(0, 0) = x[0];
  11.123 -    M(0, 1) = x[1];
  11.124 -    M(0, 2) = x[2];
  11.125 -    M(0, 3) = 0.0;
  11.126 -    M(1, 0) = y[0];
  11.127 -    M(1, 1) = y[1];
  11.128 -    M(1, 2) = y[2];
  11.129 -    M(1, 3) = 0.0;
  11.130 -    M(2, 0) = z[0];
  11.131 -    M(2, 1) = z[1];
  11.132 -    M(2, 2) = z[2];
  11.133 -    M(2, 3) = 0.0;
  11.134 -    M(3, 0) = 0.0;
  11.135 -    M(3, 1) = 0.0;
  11.136 -    M(3, 2) = 0.0;
  11.137 -    M(3, 3) = 1.0;
  11.138 -#undef M
  11.139 -    glMultMatrixf(m);
  11.140 -    
  11.141 -    /* Translate Eye to Origin */
  11.142 -    glTranslatef(-eyex, -eyey, -eyez);
  11.143 -    
  11.144 -}
  11.145 -
  11.146 -
  11.147 -
  11.148 -
  11.149 -
  11.150 -/* function to release/destroy our resources and restoring the old desktop */
  11.151 -void Quit( int returnCode )
  11.152 -{
  11.153 -    /* clean up the window */
  11.154 -    SDL_Quit( );
  11.155 -
  11.156 -    /* and exit appropriately */
  11.157 -    exit( returnCode );
  11.158 -}
  11.159 -
  11.160 -/* function to reset our viewport after a window resize */
  11.161 -int resizeWindow( int width, int height )
  11.162 -{
  11.163 -    /* Height / width ration */
  11.164 -    GLfloat ratio;
  11.165 - 
  11.166 -    /* Protect against a divide by zero */
  11.167 -   if ( height == 0 )
  11.168 -	height = 1;
  11.169 -
  11.170 -    ratio = ( GLfloat )width / ( GLfloat )height;
  11.171 -
  11.172 -    /* Setup our viewport. */
  11.173 -    glViewport( 0, 0, ( GLsizei )width, ( GLsizei )height );
  11.174 -
  11.175 -    /* change to the projection matrix and set our viewing volume. */
  11.176 -    glMatrixMode( GL_PROJECTION );
  11.177 -    glLoadIdentity( );
  11.178 -
  11.179 -    /* Set our perspective */
  11.180 -    gluPerspective( 45.0f, ratio, 0.1f, 100.0f );
  11.181 -
  11.182 -    /* Make sure we're chaning the model view and not the projection */
  11.183 -    glMatrixMode( GL_MODELVIEW );
  11.184 -
  11.185 -    /* Reset The View */
  11.186 -    glLoadIdentity( );
  11.187 -
  11.188 -    return( TRUE );
  11.189 -}
  11.190 -
  11.191 -/* function to handle key press events */
  11.192 -void handleKeyPress( SDL_keysym *keysym )
  11.193 -{
  11.194 -    switch ( keysym->sym )
  11.195 -	{
  11.196 -	case SDLK_ESCAPE:
  11.197 -	    /* ESC key was pressed */
  11.198 -	    Quit( 0 );
  11.199 -	    break;
  11.200 -	case SDLK_F1:
  11.201 -	    /* F1 key was pressed
  11.202 -	     * this toggles fullscreen mode
  11.203 -	     */
  11.204 -	    SDL_WM_ToggleFullScreen( surface );
  11.205 -	    break;
  11.206 -    case SDLK_LEFT:
  11.207 -        rotation -= 30;
  11.208 -        break;
  11.209 -
  11.210 -    case SDLK_RIGHT:
  11.211 -        rotation += 30;
  11.212 -        break;
  11.213 -        
  11.214 -	default:
  11.215 -	    break;
  11.216 -	}
  11.217 -
  11.218 -    __android_log_print(ANDROID_LOG_INFO, "SDL","Keycode: %d, %d, %d\n", keysym->sym, SDLK_LEFT, SDLK_RIGHT);
  11.219 -
  11.220 -    return;
  11.221 -}
  11.222 -
  11.223 -/* general OpenGL initialization function */
  11.224 -int initGL( GLvoid )
  11.225 -{
  11.226 -
  11.227 -    /* Enable smooth shading */
  11.228 -    glShadeModel( GL_SMOOTH );
  11.229 -
  11.230 -    /* Set the background black */
  11.231 -    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
  11.232 -
  11.233 -    /* Depth buffer setup */
  11.234 -    //glClearDepth( 1.0f );
  11.235 -
  11.236 -    /* Enables Depth Testing */
  11.237 -    glEnable( GL_DEPTH_TEST );
  11.238 -
  11.239 -    /* The Type Of Depth Test To Do */
  11.240 -    glDepthFunc( GL_LEQUAL );
  11.241 -
  11.242 -    /* Really Nice Perspective Calculations */
  11.243 -    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
  11.244 -
  11.245 -    return( TRUE );
  11.246 -}
  11.247 -
  11.248 -/* Here goes our drawing code */
  11.249 -int drawGLScene( GLvoid )
  11.250 -{
  11.251 -      
  11.252 -	static int Frames = 0;
  11.253 -	static int T0 = 0;
  11.254 -	
  11.255 -    glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  11.256 -
  11.257 -    glClearColorx(0,0,0,255);
  11.258 -    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  11.259 -
  11.260 -    glMatrixMode(GL_PROJECTION);
  11.261 -    glLoadIdentity();
  11.262 -    gluPerspective(45, (float)SCREEN_WIDTH / SCREEN_HEIGHT, 0.5f, 150);
  11.263 -
  11.264 -    glMatrixMode(GL_MODELVIEW);
  11.265 -
  11.266 -    glLoadIdentity();
  11.267 -
  11.268 -	//Camera
  11.269 -	gluLookAt(0,0,5, 0,0,0, 0,1,0);
  11.270 -			
  11.271 -	//Draw a triangle
  11.272 -	//glRotatef(iRot, 0, 1, 0);
  11.273 -
  11.274 -	glRotatef( rotation, 0.0f, 1.0f, 0.0f );
  11.275 -
  11.276 -
  11.277 -	glEnableClientState (GL_VERTEX_ARRAY);
  11.278 -	glEnableClientState (GL_COLOR_ARRAY);
  11.279 -	
  11.280 -	/* Rotate The Triangle On The Y axis ( NEW ) */
  11.281 -    //glRotatef( Frames % 360, 0.0f, 1.0f, 0.0f );
  11.282 -
  11.283 -    /* GLES variant of drawing a triangle */
  11.284 -    const GLfloat triVertices[][9] = {
  11.285 -      {     /* Front Triangle */
  11.286 -	 0.0f,  1.0f,  0.0f,               /* Top Of Triangle               */
  11.287 -	-1.0f, -1.0f,  1.0f,               /* Left Of Triangle              */
  11.288 -	 1.0f, -1.0f,  1.0f                /* Right Of Triangle             */
  11.289 -      }, {  /* Right Triangle */
  11.290 -	 0.0f,  1.0f,  0.0f,               /* Top Of Triangle               */
  11.291 -	 1.0f, -1.0f,  1.0f,               /* Left Of Triangle              */
  11.292 -	 1.0f, -1.0f, -1.0f                /* Right Of Triangle             */
  11.293 -      }, {  /* Back Triangle */
  11.294 -	 0.0f,  1.0f,  0.0f,               /* Top Of Triangle               */
  11.295 -	 1.0f, -1.0f, -1.0f,               /* Left Of Triangle              */
  11.296 -	-1.0f, -1.0f, -1.0f                /* Right Of Triangle             */
  11.297 -      }, {  /* Left Triangle */
  11.298 -	 0.0f,  1.0f,  0.0f,               /* Top Of Triangle               */
  11.299 -	-1.0f, -1.0f, -1.0f,               /* Left Of Triangle              */
  11.300 -	-1.0f, -1.0f,  1.0f                /* Right Of Triangle             */
  11.301 -      }
  11.302 -    };
  11.303 -
  11.304 -    /* unlike GL, GLES does not support RGB. We have to use RGBA instead */
  11.305 -    const GLfloat triColors[][12] = {
  11.306 -      {     /* Front triangle */
  11.307 -        1.0f, 0.0f, 0.0f, 1.0f,            /* Red                           */
  11.308 -	0.0f, 1.0f, 0.0f, 1.0f,            /* Green                         */
  11.309 -	0.0f, 0.0f, 1.0f, 1.0f             /* Blue                          */
  11.310 -      }, {  /* Right triangle */
  11.311 -        1.0f, 0.0f, 0.0f, 1.0f,            /* Red                           */
  11.312 -	0.0f, 0.0f, 1.0f, 1.0f,            /* Blue                          */
  11.313 -	0.0f, 1.0f, 0.0f, 1.0f             /* Green                         */
  11.314 -      }, {  /* Back triangle */
  11.315 -        1.0f, 0.0f, 0.0f, 1.0f,            /* Red                           */
  11.316 -	0.0f, 1.0f, 0.0f, 1.0f,            /* Green                         */
  11.317 -	0.0f, 0.0f, 1.0f, 1.0f             /* Blue                          */
  11.318 -      }, {  /* Left triangle */
  11.319 -        1.0f, 0.0f, 0.0f, 1.0f,            /* Red                           */
  11.320 -	0.0f, 0.0f, 1.0f, 1.0f,            /* Blue                          */
  11.321 -	0.0f, 1.0f, 0.0f, 1.0f             /* Green                         */
  11.322 -      }
  11.323 -    };
  11.324 -
  11.325 -    glEnableClientState(GL_COLOR_ARRAY);
  11.326 -
  11.327 -    int tri=0;
  11.328 -
  11.329 -    /* Loop through all Triangles */
  11.330 -    for(tri=0;tri<sizeof(triVertices)/(9*sizeof(GLfloat));tri++) 
  11.331 -    {
  11.332 -      glVertexPointer(3, GL_FLOAT, 0, triVertices[tri]);
  11.333 -      glColorPointer(4, GL_FLOAT, 0, triColors[tri]);
  11.334 -      
  11.335 -      glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
  11.336 -    }
  11.337 -		
  11.338 -    //__android_log_print(ANDROID_LOG_INFO, "SDL", "render %d", Frames++);
  11.339 -
  11.340 -    /* Draw it to the screen */
  11.341 -    SDL_GL_SwapBuffers( );
  11.342 -
  11.343 -    /* Gather our frames per second */
  11.344 -    Frames++;
  11.345 -    {
  11.346 -	GLint t = SDL_GetTicks();
  11.347 -	if (t - T0 >= 5000) {
  11.348 -	    GLfloat seconds = (t - T0) / 1000.0;
  11.349 -	    GLfloat fps = Frames / seconds;
  11.350 -	    __android_log_print(ANDROID_LOG_INFO, "SDL","%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
  11.351 -	    T0 = t;
  11.352 -	    Frames = 0;
  11.353 -	}
  11.354 -    }
  11.355 -
  11.356 -    rotation++;
  11.357 -
  11.358 -    return( TRUE );
  11.359 -}
  11.360 -
  11.361 -
  11.362 -struct
  11.363 -{
  11.364 -    SDL_AudioSpec spec;
  11.365 -    Uint8 *sound;               /* Pointer to wave data */
  11.366 -    Uint32 soundlen;            /* Length of wave data */
  11.367 -    int soundpos;               /* Current play position */
  11.368 -} wave;
  11.369 -
  11.370 -void SDLCALL
  11.371 -fillerup(void *unused, Uint8 * stream, int len)
  11.372 -{
  11.373 -    __android_log_print(ANDROID_LOG_INFO, "SDL","FILLERUP\n");
  11.374 -    
  11.375 -    Uint8 *waveptr;
  11.376 -    int waveleft;
  11.377 -
  11.378 -    /* Set up the pointers */
  11.379 -    waveptr = wave.sound + wave.soundpos;
  11.380 -    waveleft = wave.soundlen - wave.soundpos;
  11.381 -
  11.382 -    /* Go! */
  11.383 -    while (waveleft <= len) {
  11.384 -        SDL_memcpy(stream, waveptr, waveleft);
  11.385 -        stream += waveleft;
  11.386 -        len -= waveleft;
  11.387 -        waveptr = wave.sound;
  11.388 -        waveleft = wave.soundlen;
  11.389 -        wave.soundpos = 0;
  11.390 -    }
  11.391 -    SDL_memcpy(stream, waveptr, len);
  11.392 -    wave.soundpos += len;
  11.393 -}
  11.394 -
  11.395 -void testAudio(){
  11.396 -
  11.397 -    const char *file = "/sdcard/sample.wav";
  11.398 -
  11.399 -    /* Load the SDL library */
  11.400 -    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
  11.401 -        __android_log_print(ANDROID_LOG_INFO, "SDL","Couldn't initialize SDL Audio: %s\n", SDL_GetError());
  11.402 -        return;
  11.403 -    }else{
  11.404 -        __android_log_print(ANDROID_LOG_INFO, "SDL","Init audio ok\n");
  11.405 -    }
  11.406 -
  11.407 -    /* Load the wave file into memory */
  11.408 -    if (SDL_LoadWAV(file, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
  11.409 -        __android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't load %s: %s\n", file, SDL_GetError());
  11.410 -        return;
  11.411 -    }
  11.412 -
  11.413 -    wave.spec.callback = fillerup;
  11.414 -
  11.415 -    __android_log_print(ANDROID_LOG_INFO, "SDL","Loaded: %d\n", wave.soundlen);
  11.416 -
  11.417 -
  11.418 -    /* Initialize fillerup() variables */
  11.419 -    if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
  11.420 -        __android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't open audio: %s\n", SDL_GetError());
  11.421 -        SDL_FreeWAV(wave.sound);
  11.422 -        return;
  11.423 -    }
  11.424 -
  11.425 -     __android_log_print(ANDROID_LOG_INFO, "SDL","Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
  11.426 -
  11.427 -    /* Let the audio run */
  11.428 -    SDL_PauseAudio(0);
  11.429 -
  11.430 -     __android_log_print(ANDROID_LOG_INFO, "SDL","Playing\n");
  11.431 -    
  11.432 -    while (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING){
  11.433 -         //__android_log_print(ANDROID_LOG_INFO, "SDL","Still playing\n");
  11.434 -        SDL_Delay(100);
  11.435 -    }
  11.436 -
  11.437 -     __android_log_print(ANDROID_LOG_INFO, "SDL","Closing down\n");
  11.438 -
  11.439 -    /* Clean up on signal */
  11.440 -    SDL_CloseAudio();
  11.441 -    SDL_FreeWAV(wave.sound);
  11.442 -}
  11.443 -
  11.444 -int SDL_main( int argc, char **argv )
  11.445 -{
  11.446 -
  11.447 -	__android_log_print(ANDROID_LOG_INFO, "SDL","entry\n");
  11.448 -
  11.449 -    /* Flags to pass to SDL_SetVideoMode */
  11.450 -    int videoFlags;
  11.451 -    /* main loop variable */
  11.452 -    int done = FALSE;
  11.453 -    /* used to collect events */
  11.454 -    SDL_Event event;
  11.455 -    /* this holds some info about our display */
  11.456 -    const SDL_VideoInfo *videoInfo;
  11.457 -    /* whether or not the window is active */
  11.458 -    int isActive = TRUE;
  11.459 -
  11.460 -    /* initialize SDL */
  11.461 -    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  11.462 -	{
  11.463 -	    __android_log_print(ANDROID_LOG_INFO, "SDL", "Video initialization failed: %s\n",
  11.464 -		     SDL_GetError( ) );
  11.465 -	    Quit( 1 );
  11.466 -	}
  11.467 -
  11.468 -    /* Fetch the video info */
  11.469 -    videoInfo = SDL_GetVideoInfo( );
  11.470 -
  11.471 -    if ( !videoInfo )
  11.472 -	{
  11.473 -	    __android_log_print(ANDROID_LOG_INFO, "SDL", "Video query failed: %s\n",
  11.474 -		     SDL_GetError( ) );
  11.475 -	    Quit( 1 );
  11.476 -	}
  11.477 -
  11.478 -    /* the flags to pass to SDL_SetVideoMode */
  11.479 -    videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
  11.480 -    videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
  11.481 -    videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
  11.482 -    videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */
  11.483 -
  11.484 -    /* This checks to see if surfaces can be stored in memory */
  11.485 -    if ( videoInfo->hw_available )
  11.486 -	videoFlags |= SDL_HWSURFACE;
  11.487 -    else
  11.488 -	videoFlags |= SDL_SWSURFACE;
  11.489 -
  11.490 -    /* This checks if hardware blits can be done */
  11.491 -    if ( videoInfo->blit_hw )
  11.492 -	videoFlags |= SDL_HWACCEL;
  11.493 -
  11.494 -    /* Sets up OpenGL double buffering */
  11.495 -    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
  11.496 -
  11.497 -    /* get a SDL surface */
  11.498 -    surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,
  11.499 -				videoFlags );
  11.500 -
  11.501 -    /* Verify there is a surface */
  11.502 -    if ( !surface )
  11.503 -	{
  11.504 -	    __android_log_print(ANDROID_LOG_INFO, "SDL",  "Video mode set failed: %s\n", SDL_GetError( ) );
  11.505 -	    Quit( 1 );
  11.506 -	}
  11.507 -
  11.508 -	__android_log_print(ANDROID_LOG_INFO, "SDL","Made a video mode!\n");
  11.509 -
  11.510 -    /* initialize OpenGL */
  11.511 -    initGL( );
  11.512 -
  11.513 -    /* resize the initial window */
  11.514 -    resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT );
  11.515 -
  11.516 -
  11.517 -    //testAudio();
  11.518 -
  11.519 -
  11.520 -    /* wait for events */ 
  11.521 -    while ( !done )
  11.522 -	{
  11.523 -	    /* handle the events in the queue */
  11.524 -
  11.525 -	    while ( SDL_PollEvent( &event ) )
  11.526 -		{
  11.527 -		    switch( event.type )
  11.528 -			{
  11.529 -			case SDL_ACTIVEEVENT:
  11.530 -			    /* Something's happend with our focus
  11.531 -			     * If we lost focus or we are iconified, we
  11.532 -			     * shouldn't draw the screen
  11.533 -			     */
  11.534 -			    if ( event.active.gain == 0 )
  11.535 -				isActive = FALSE;
  11.536 -			    else
  11.537 -				isActive = TRUE;
  11.538 -			    break;			    
  11.539 -			case SDL_VIDEORESIZE:
  11.540 -			    /* handle resize event */
  11.541 -			    surface = SDL_SetVideoMode( event.resize.w,
  11.542 -							event.resize.h,
  11.543 -							16, videoFlags );
  11.544 -			    if ( !surface )
  11.545 -				{
  11.546 -				    __android_log_print(ANDROID_LOG_INFO, "SDL","Could not get a surface after resize: %s\n", SDL_GetError( ) );
  11.547 -				    Quit( 1 );
  11.548 -				}
  11.549 -			    resizeWindow( event.resize.w, event.resize.h );
  11.550 -			    break;
  11.551 -			case SDL_KEYDOWN:
  11.552 -			    /* handle key presses */
  11.553 -			    handleKeyPress( &event.key.keysym );
  11.554 -			    break;
  11.555 -			case SDL_QUIT:
  11.556 -			    /* handle quit requests */
  11.557 -			    done = TRUE;
  11.558 -			    __android_log_print(ANDROID_LOG_INFO, "SDL","App is shutting down\n");
  11.559 -			    break;
  11.560 -			default:
  11.561 -			    break;
  11.562 -			}
  11.563 -		}
  11.564 -
  11.565 -	    /* draw the scene */
  11.566 -	    if ( isActive )
  11.567 -		drawGLScene( );
  11.568 -	}
  11.569 -
  11.570 -    /* clean ourselves up and exit */
  11.571 -    Quit( 0 );
  11.572 -
  11.573 -    /* Should never get here */
  11.574 -    return( 0 );
  11.575 -}
  11.576 -
  11.577 -
    12.1 --- a/android/project/local.properties	Wed Jan 05 00:09:19 2011 -0800
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,10 +0,0 @@
    12.4 -# This file is automatically generated by Android Tools.
    12.5 -# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
    12.6 -# 
    12.7 -# This file must *NOT* be checked in Version Control Systems,
    12.8 -# as it contains information specific to your local configuration.
    12.9 -
   12.10 -# location of the SDK. This is only used by Ant
   12.11 -# For customization when using a Version Control System, please read the
   12.12 -# header note.
   12.13 -sdk.dir=/home/paul/Projects/gsoc/sdk/android-sdk-linux_86
    13.1 Binary file android/project/res/drawable-hdpi/icon.png has changed
    14.1 Binary file android/project/res/drawable-ldpi/icon.png has changed
    15.1 Binary file android/project/res/drawable-mdpi/icon.png has changed
    16.1 --- a/android/project/res/layout/main.xml	Wed Jan 05 00:09:19 2011 -0800
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,13 +0,0 @@
    16.4 -<?xml version="1.0" encoding="utf-8"?>
    16.5 -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    16.6 -    android:orientation="vertical"
    16.7 -    android:layout_width="fill_parent"
    16.8 -    android:layout_height="fill_parent"
    16.9 -    >
   16.10 -<TextView  
   16.11 -    android:layout_width="fill_parent" 
   16.12 -    android:layout_height="wrap_content" 
   16.13 -    android:text="Hello World, SDLActivity"
   16.14 -    />
   16.15 -</LinearLayout>
   16.16 -
    17.1 --- a/android/project/res/values/strings.xml	Wed Jan 05 00:09:19 2011 -0800
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,4 +0,0 @@
    17.4 -<?xml version="1.0" encoding="utf-8"?>
    17.5 -<resources>
    17.6 -    <string name="app_name">SDLActivity</string>
    17.7 -</resources>
    18.1 --- a/android/project/src/org/libsdl/app/SDLActivity.java	Wed Jan 05 00:09:19 2011 -0800
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,388 +0,0 @@
    18.4 -package org.libsdl.app;
    18.5 -
    18.6 -import javax.microedition.khronos.egl.EGLConfig;
    18.7 -import javax.microedition.khronos.opengles.GL10;
    18.8 -import javax.microedition.khronos.egl.*;
    18.9 -
   18.10 -import android.app.*;
   18.11 -import android.content.*;
   18.12 -import android.view.*;
   18.13 -import android.os.*;
   18.14 -import android.util.Log;
   18.15 -import android.graphics.*;
   18.16 -import android.text.method.*;
   18.17 -import android.text.*;
   18.18 -import android.media.*;
   18.19 -import android.hardware.*;
   18.20 -import android.content.*;
   18.21 -
   18.22 -import java.lang.*;
   18.23 -
   18.24 -
   18.25 -/**
   18.26 -    SDL Activity
   18.27 -*/
   18.28 -public class SDLActivity extends Activity {
   18.29 -
   18.30 -    //Main components
   18.31 -    private static SDLActivity mSingleton;
   18.32 -    private static SDLSurface mSurface;
   18.33 -
   18.34 -    //Audio
   18.35 -    private static AudioTrack mAudioTrack;
   18.36 -    private static boolean bAudioIsEnabled;
   18.37 -
   18.38 -    //Sensors
   18.39 -    private static boolean bAccelIsEnabled;
   18.40 -
   18.41 -    //feature IDs. Must match up on the C side as well.
   18.42 -    private static int FEATURE_AUDIO = 1;
   18.43 -    private static int FEATURE_ACCEL = 2;
   18.44 -
   18.45 -    //Load the .so
   18.46 -    static {
   18.47 -        System.loadLibrary("sdlapp");
   18.48 -    }
   18.49 -
   18.50 -    //Setup
   18.51 -    protected void onCreate(Bundle savedInstanceState) {
   18.52 -        super.onCreate(savedInstanceState);
   18.53 -        
   18.54 -        //So we can call stuff from static callbacks
   18.55 -        mSingleton = this;
   18.56 -
   18.57 -        //Set up the surface
   18.58 -        mSurface = new SDLSurface(getApplication());
   18.59 -        setContentView(mSurface);
   18.60 -        SurfaceHolder holder = mSurface.getHolder();
   18.61 -        holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
   18.62 -        
   18.63 -    }
   18.64 -
   18.65 -    //Audio
   18.66 -    public static boolean initAudio(){        
   18.67 -
   18.68 -        //blah. Hardcoded things are bad. FIXME when we have more sound stuff
   18.69 -        //working properly. 
   18.70 -        mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
   18.71 -                    11025,
   18.72 -                    AudioFormat.CHANNEL_CONFIGURATION_MONO,
   18.73 -                    AudioFormat.ENCODING_PCM_8BIT,
   18.74 -                    2048,
   18.75 -                    AudioTrack.MODE_STREAM);   
   18.76 -        bAudioIsEnabled = true;     
   18.77 -        return true;
   18.78 -    }
   18.79 -
   18.80 -    //Accel
   18.81 -    public static boolean initAccel(){
   18.82 -        mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
   18.83 -        bAccelIsEnabled = true;
   18.84 -        return true;
   18.85 -    }
   18.86 -    
   18.87 -    public static boolean closeAccel(){
   18.88 -        mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, false);
   18.89 -        bAccelIsEnabled = false;
   18.90 -        return true;
   18.91 -    }
   18.92 -    
   18.93 -
   18.94 -    //Events
   18.95 -    protected void onPause() {
   18.96 -        super.onPause();
   18.97 -    }
   18.98 -
   18.99 -    protected void onResume() {
  18.100 -        super.onResume();
  18.101 -    }
  18.102 -
  18.103 -    
  18.104 -
  18.105 -
  18.106 -
  18.107 -    //C functions we call
  18.108 -    public static native void nativeInit();
  18.109 -    public static native void nativeQuit();
  18.110 -    public static native void nativeSetScreenSize(int width, int height);
  18.111 -    public static native void onNativeKeyDown(int keycode);
  18.112 -    public static native void onNativeKeyUp(int keycode);
  18.113 -    public static native void onNativeTouch(int action, float x, 
  18.114 -                                            float y, float p);
  18.115 -    public static native void onNativeResize(int x, int y, int format);
  18.116 -    public static native void onNativeAccel(float x, float y, float z);
  18.117 -
  18.118 -
  18.119 -
  18.120 -    //Java functions called from C
  18.121 -    private static void createGLContext(){
  18.122 -        mSurface.initEGL();
  18.123 -    }
  18.124 -
  18.125 -    public static void flipBuffers(){
  18.126 -        mSurface.flipEGL();
  18.127 -    }
  18.128 -
  18.129 -    public static void updateAudio(byte [] buf){
  18.130 -    
  18.131 -        if(mAudioTrack == null){
  18.132 -            return;
  18.133 -        }
  18.134 -        
  18.135 -        mAudioTrack.write(buf, 0, buf.length);
  18.136 -        mAudioTrack.play();
  18.137 -        
  18.138 -        Log.v("SDL","Played some audio");
  18.139 -    }
  18.140 -
  18.141 -    public static void enableFeature(int featureid, int enabled){
  18.142 -         Log.v("SDL","Feature " + featureid + " = " + enabled);
  18.143 -
  18.144 -        //Yuck. This is all horribly inelegent. If it gets to more than a few
  18.145 -        //'features' I'll rip this out and make something nicer, I promise :)
  18.146 -        if(featureid == FEATURE_AUDIO){
  18.147 -            if(enabled == 1){
  18.148 -                initAudio();
  18.149 -            }else{
  18.150 -                //We don't have one of these yet...
  18.151 -                //closeAudio(); 
  18.152 -            }
  18.153 -        }
  18.154 -
  18.155 -        else if(featureid == FEATURE_ACCEL){
  18.156 -            if(enabled == 1){
  18.157 -                initAccel();
  18.158 -            }else{
  18.159 -                closeAccel();
  18.160 -            }
  18.161 -        }
  18.162 -    }
  18.163 -
  18.164 -
  18.165 -
  18.166 -
  18.167 -
  18.168 -    
  18.169 -    
  18.170 -}
  18.171 -
  18.172 -/**
  18.173 -    Simple nativeInit() runnable
  18.174 -*/
  18.175 -class SDLRunner implements Runnable{
  18.176 -    public void run(){
  18.177 -        //SDLActivity.initAudio();
  18.178 -        
  18.179 -        //Runs SDL_main()
  18.180 -        SDLActivity.nativeInit();
  18.181 -
  18.182 -        Log.v("SDL","SDL thread terminated");
  18.183 -    }
  18.184 -}
  18.185 -
  18.186 -
  18.187 -/**
  18.188 -    SDLSurface. This is what we draw on, so we need to know when it's created
  18.189 -    in order to do anything useful. 
  18.190 -
  18.191 -    Because of this, that's where we set up the SDL thread
  18.192 -*/
  18.193 -class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, 
  18.194 -    View.OnKeyListener, View.OnTouchListener, SensorEventListener  {
  18.195 -
  18.196 -    //This is what SDL runs in. It invokes SDL_main(), eventually
  18.197 -    private Thread mSDLThread;    
  18.198 -    
  18.199 -    //EGL private objects
  18.200 -    private EGLContext  mEGLContext;
  18.201 -    private EGLSurface  mEGLSurface;
  18.202 -    private EGLDisplay  mEGLDisplay;
  18.203 -
  18.204 -    //Sensors
  18.205 -    private static SensorManager mSensorManager;
  18.206 -
  18.207 -    //Startup    
  18.208 -    public SDLSurface(Context context) {
  18.209 -        super(context);
  18.210 -        getHolder().addCallback(this); 
  18.211 -    
  18.212 -        setFocusable(true);
  18.213 -        setFocusableInTouchMode(true);
  18.214 -        requestFocus();
  18.215 -        setOnKeyListener(this); 
  18.216 -        setOnTouchListener(this);   
  18.217 -        
  18.218 -        mSensorManager = (SensorManager)context.getSystemService("sensor");  
  18.219 -    }
  18.220 -
  18.221 -    //Called when we have a valid drawing surface
  18.222 -    public void surfaceCreated(SurfaceHolder holder) {
  18.223 -        Log.v("SDL","Surface created"); 
  18.224 -
  18.225 -        int width = getWidth();
  18.226 -        int height = getHeight();
  18.227 -
  18.228 -        //Set the width and height variables in C before we start SDL so we have
  18.229 -        //it available on init
  18.230 -        SDLActivity.nativeSetScreenSize(width, height);
  18.231 -
  18.232 -        //Now start up the C app thread
  18.233 -        mSDLThread = new Thread(new SDLRunner(), "SDLThread"); 
  18.234 -		mSDLThread.start();       
  18.235 -    }
  18.236 -
  18.237 -    //Called when we lose the surface
  18.238 -    public void surfaceDestroyed(SurfaceHolder holder) {
  18.239 -        Log.v("SDL","Surface destroyed");
  18.240 -        
  18.241 -        SDLActivity.nativeQuit();
  18.242 -
  18.243 -        //Now wait for the SDL thread to quit
  18.244 -        try{
  18.245 -            mSDLThread.wait();
  18.246 -        }catch(Exception e){
  18.247 -            Log.v("SDL","Problem stopping thread: " + e);
  18.248 -        }
  18.249 -    }
  18.250 -
  18.251 -    //Called when the surface is resized
  18.252 -    public void surfaceChanged(SurfaceHolder holder, int format, 
  18.253 -                                int width, int height) {
  18.254 -        Log.v("SDL","Surface resized");
  18.255 -        
  18.256 -        SDLActivity.onNativeResize(width, height, format);
  18.257 -    }
  18.258 -
  18.259 -    //unused
  18.260 -    public void onDraw(Canvas canvas) {}
  18.261 -
  18.262 -    
  18.263 -    //EGL functions
  18.264 -    public boolean initEGL(){
  18.265 -        Log.v("SDL","Starting up");
  18.266 -
  18.267 -        try{
  18.268 -
  18.269 -            EGL10 egl = (EGL10)EGLContext.getEGL();
  18.270 -
  18.271 -            EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
  18.272 -
  18.273 -            int[] version = new int[2];
  18.274 -            egl.eglInitialize(dpy, version);
  18.275 -
  18.276 -            int[] configSpec = {
  18.277 -                    //EGL10.EGL_DEPTH_SIZE,   16,
  18.278 -                    EGL10.EGL_NONE
  18.279 -            };
  18.280 -            EGLConfig[] configs = new EGLConfig[1];
  18.281 -            int[] num_config = new int[1];
  18.282 -            egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
  18.283 -            EGLConfig config = configs[0];
  18.284 -
  18.285 -            EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);
  18.286 -
  18.287 -            EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null);
  18.288 -
  18.289 -            egl.eglMakeCurrent(dpy, surface, surface, ctx);
  18.290 -
  18.291 -            mEGLContext = ctx;
  18.292 -            mEGLDisplay = dpy;
  18.293 -            mEGLSurface = surface;
  18.294 -            
  18.295 -            
  18.296 -        }catch(Exception e){
  18.297 -            Log.v("SDL", e + "");
  18.298 -            for(StackTraceElement s : e.getStackTrace()){
  18.299 -                Log.v("SDL", s.toString());
  18.300 -            }
  18.301 -        }
  18.302 -        Log.v("SDL","Done making!");
  18.303 -
  18.304 -        return true;
  18.305 -    }
  18.306 -
  18.307 -    //EGL buffer flip
  18.308 -    public void flipEGL(){      
  18.309 -        try{
  18.310 -        
  18.311 -            EGL10 egl = (EGL10)EGLContext.getEGL();
  18.312 -            GL10 gl = (GL10)mEGLContext.getGL();
  18.313 -
  18.314 -            egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
  18.315 -
  18.316 -            //drawing here
  18.317 -
  18.318 -            egl.eglWaitGL();
  18.319 -
  18.320 -            egl.eglSwapBuffers(mEGLDisplay, mEGLSurface);
  18.321 -
  18.322 -            
  18.323 -        }catch(Exception e){
  18.324 -            Log.v("SDL", "flipEGL(): " + e);
  18.325 -
  18.326 -            for(StackTraceElement s : e.getStackTrace()){
  18.327 -                Log.v("SDL", s.toString());
  18.328 -            }
  18.329 -        }
  18.330 -    }
  18.331 -
  18.332 -
  18.333 -  
  18.334 -    //Key events
  18.335 -    public boolean onKey(View  v, int keyCode, KeyEvent event){
  18.336 -
  18.337 -        if(event.getAction() == KeyEvent.ACTION_DOWN){
  18.338 -            SDLActivity.onNativeKeyDown(keyCode);
  18.339 -            return true;
  18.340 -        }
  18.341 -        
  18.342 -        else if(event.getAction() == KeyEvent.ACTION_UP){
  18.343 -            SDLActivity.onNativeKeyUp(keyCode);
  18.344 -            return true;
  18.345 -        }
  18.346 -        
  18.347 -        return false;
  18.348 -    }
  18.349 -
  18.350 -    //Touch events
  18.351 -    public boolean onTouch(View v, MotionEvent event){
  18.352 -    
  18.353 -        int action = event.getAction();
  18.354 -        float x = event.getX();
  18.355 -        float y = event.getY();
  18.356 -        float p = event.getPressure();
  18.357 -
  18.358 -        //TODO: Anything else we need to pass?        
  18.359 -        SDLActivity.onNativeTouch(action, x, y, p);
  18.360 -        return true;
  18.361 -    }
  18.362 -
  18.363 -    //Sensor events
  18.364 -    public void enableSensor(int sensortype, boolean enabled){
  18.365 -        //TODO: This uses getDefaultSensor - what if we have >1 accels?
  18.366 -        if(enabled){
  18.367 -            mSensorManager.registerListener(this, 
  18.368 -                            mSensorManager.getDefaultSensor(sensortype), 
  18.369 -                            SensorManager.SENSOR_DELAY_GAME, null);
  18.370 -        }else{
  18.371 -            mSensorManager.unregisterListener(this, 
  18.372 -                            mSensorManager.getDefaultSensor(sensortype));
  18.373 -        }
  18.374 -    }
  18.375 -    
  18.376 -    public void onAccuracyChanged(Sensor sensor, int accuracy){
  18.377 -        //TODO
  18.378 -    }
  18.379 -
  18.380 -    public void onSensorChanged(SensorEvent event){
  18.381 -        if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
  18.382 -            SDLActivity.onNativeAccel(  event.values[0],
  18.383 -                                        event.values[1],
  18.384 -                                        event.values[2] );
  18.385 -        }
  18.386 -    }
  18.387 -
  18.388 -
  18.389 -}
  18.390 -
  18.391 -
    19.1 --- a/include/SDL_config_android.h	Wed Jan 05 00:09:19 2011 -0800
    19.2 +++ b/include/SDL_config_android.h	Thu Jan 06 16:11:21 2011 -0800
    19.3 @@ -127,7 +127,7 @@
    19.4  #define SDL_HAPTIC_DUMMY	1
    19.5  
    19.6  /* Enable various shared object loading systems */
    19.7 -#define SDL_LOADSO_DUMMY	1
    19.8 +#define SDL_LOADSO_DLOPEN	1
    19.9  
   19.10  /* Enable various threading systems */
   19.11  #define SDL_THREAD_PTHREAD	1
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/SDL_android.cpp	Thu Jan 06 16:11:21 2011 -0800
    20.3 @@ -0,0 +1,231 @@
    20.4 +/*
    20.5 +    SDL - Simple DirectMedia Layer
    20.6 +    Copyright (C) 1997-2010 Sam Lantinga
    20.7 +
    20.8 +    This library is free software; you can redistribute it and/or
    20.9 +    modify it under the terms of the GNU Lesser General Public
   20.10 +    License as published by the Free Software Foundation; either
   20.11 +    version 2.1 of the License, or (at your option) any later version.
   20.12 +
   20.13 +    This library is distributed in the hope that it will be useful,
   20.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20.16 +    Lesser General Public License for more details.
   20.17 +
   20.18 +    You should have received a copy of the GNU Lesser General Public
   20.19 +    License along with this library; if not, write to the Free Software
   20.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   20.21 +
   20.22 +    Sam Lantinga
   20.23 +    slouken@libsdl.org
   20.24 +*/
   20.25 +#include "SDL_config.h"
   20.26 +
   20.27 +/*******************************************************************************
   20.28 + This file links the Java side of Android with libsdl
   20.29 +*******************************************************************************/
   20.30 +#include <jni.h>
   20.31 +#include <android/log.h>
   20.32 +
   20.33 +
   20.34 +/*******************************************************************************
   20.35 +                               Globals
   20.36 +*******************************************************************************/
   20.37 +JavaVM* mVM = NULL;
   20.38 +JNIEnv* mEnv = NULL;
   20.39 +JNIEnv* mAudioThreadEnv = NULL; //See the note below for why this is necessary
   20.40 +
   20.41 +//Main activity
   20.42 +jclass mActivityInstance;
   20.43 +
   20.44 +//method signatures
   20.45 +jmethodID midCreateGLContext;
   20.46 +jmethodID midFlipBuffers;
   20.47 +jmethodID midEnableFeature;
   20.48 +jmethodID midUpdateAudio;
   20.49 +
   20.50 +extern "C" int Android_OnKeyDown(int keycode);
   20.51 +extern "C" int Android_OnKeyUp(int keycode);
   20.52 +extern "C" void Android_SetScreenResolution(int width, int height);
   20.53 +extern "C" void Android_OnResize(int width, int height, int format);
   20.54 +extern "C" int SDL_SendQuit();
   20.55 +extern "C" void Android_EnableFeature(int featureid, bool enabled);
   20.56 +
   20.57 +//If we're not the active app, don't try to render
   20.58 +bool bRenderingEnabled = false;
   20.59 +
   20.60 +//Feature IDs
   20.61 +static const int FEATURE_AUDIO = 1;
   20.62 +static const int FEATURE_ACCEL = 2;
   20.63 +
   20.64 +//Accelerometer data storage
   20.65 +float fLastAccelerometer[3];
   20.66 +
   20.67 +
   20.68 +/*******************************************************************************
   20.69 +                 Functions called by JNI
   20.70 +*******************************************************************************/
   20.71 +
   20.72 +// Library init
   20.73 +extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
   20.74 +{
   20.75 +    mVM = vm;
   20.76 +
   20.77 +    return JNI_VERSION_1_4;
   20.78 +}
   20.79 +
   20.80 +// Called before SDL_main() to initialize JNI bindings
   20.81 +extern "C" void SDL_Android_Init(JNIEnv* env)
   20.82 +{
   20.83 +    mEnv = env;
   20.84 +
   20.85 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()");
   20.86 +
   20.87 +    jclass cls = mEnv->FindClass ("org/libsdl/app/SDLActivity"); 
   20.88 +    mActivityInstance = cls;
   20.89 +    midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
   20.90 +    midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
   20.91 +    midEnableFeature = mEnv->GetStaticMethodID(cls,"enableFeature","(II)V");
   20.92 +    midUpdateAudio = mEnv->GetStaticMethodID(cls,"updateAudio","([B)V");
   20.93 +
   20.94 +    if(!midCreateGLContext || !midFlipBuffers || !midEnableFeature ||
   20.95 +        !midUpdateAudio) {
   20.96 +        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n");
   20.97 +    } else {
   20.98 +#ifdef DEBUG
   20.99 +        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Good mids\n");
  20.100 +#endif
  20.101 +    }
  20.102 +}
  20.103 +
  20.104 +// Keydown
  20.105 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown(JNIEnv* env, 
  20.106 +               jobject obj, jint keycode)
  20.107 +{
  20.108 +    int r = Android_OnKeyDown(keycode);
  20.109 +#ifdef DEBUG
  20.110 +    __android_log_print(ANDROID_LOG_INFO, "SDL", 
  20.111 +                        "SDL: native key down %d, %d\n", keycode, r);
  20.112 +#endif
  20.113 +}
  20.114 +
  20.115 +// Keyup
  20.116 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp(JNIEnv* env, 
  20.117 +               jobject obj, jint keycode)
  20.118 +{
  20.119 +    int r = Android_OnKeyUp(keycode);
  20.120 +#ifdef DEBUG
  20.121 +    __android_log_print(ANDROID_LOG_INFO, "SDL", 
  20.122 +                        "SDL: native key up %d, %d\n", keycode, r);
  20.123 +#endif
  20.124 +}
  20.125 +
  20.126 +// Touch
  20.127 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(JNIEnv* env, 
  20.128 +               jobject obj, jint action, jfloat x, jfloat y, jfloat p)
  20.129 +{
  20.130 +#ifdef DEBUG
  20.131 +    __android_log_print(ANDROID_LOG_INFO, "SDL", 
  20.132 +                        "SDL: native touch event %d @ %f/%f, pressure %f\n", 
  20.133 +                        action, x, y, p);
  20.134 +#endif
  20.135 +
  20.136 +    //TODO: Pass this off to the SDL multitouch stuff
  20.137 +}
  20.138 +
  20.139 +// Quit
  20.140 +extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit( JNIEnv*  env, 
  20.141 +                                                                jobject obj )
  20.142 +{    
  20.143 +    // Stop rendering as we're no longer in the foreground
  20.144 +    bRenderingEnabled = false;
  20.145 +
  20.146 +    // Inject a SDL_QUIT event
  20.147 +    SDL_SendQuit();
  20.148 +}
  20.149 +
  20.150 +// Screen size
  20.151 +extern "C" void Java_org_libsdl_app_SDLActivity_nativeSetScreenSize(
  20.152 +                JNIEnv*  env, jobject obj, jint width, jint height)
  20.153 +{
  20.154 +    __android_log_print(ANDROID_LOG_INFO, "SDL", 
  20.155 +                        "SDL: Set screen size on init: %d/%d\n", width, height);
  20.156 +    Android_SetScreenResolution(width, height);
  20.157 +}
  20.158 +
  20.159 +// Resize
  20.160 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize(
  20.161 +                                        JNIEnv*  env, jobject obj, jint width, 
  20.162 +                                        jint height, jint format)
  20.163 +{
  20.164 +    Android_OnResize(width, height, format);
  20.165 +}
  20.166 +
  20.167 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
  20.168 +                                        JNIEnv*  env, jobject obj,
  20.169 +                                        jfloat x, jfloat y, jfloat z)
  20.170 +{
  20.171 +    fLastAccelerometer[0] = x;
  20.172 +    fLastAccelerometer[1] = y;
  20.173 +    fLastAccelerometer[2] = z;   
  20.174 +}
  20.175 +
  20.176 +
  20.177 +
  20.178 +/*******************************************************************************
  20.179 +             Functions called by SDL into Java
  20.180 +*******************************************************************************/
  20.181 +extern "C" void Android_CreateContext()
  20.182 +{
  20.183 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n");
  20.184 +
  20.185 +    bRenderingEnabled = true;
  20.186 +
  20.187 +    mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext ); 
  20.188 +}
  20.189 +
  20.190 +extern "C" void Android_Render()
  20.191 +{
  20.192 +    if (!bRenderingEnabled) {
  20.193 +        return;
  20.194 +    }
  20.195 +
  20.196 +    // When we get here, we've accumulated a full frame    
  20.197 +    mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers); 
  20.198 +}
  20.199 +
  20.200 +extern "C" void Android_EnableFeature(int featureid, bool enabled)
  20.201 +{
  20.202 +    mEnv->CallStaticVoidMethod(mActivityInstance, midEnableFeature, 
  20.203 +                                featureid, (int)enabled); 
  20.204 +}
  20.205 +
  20.206 +extern "C" void Android_UpdateAudioBuffer(unsigned char *buf, int len)
  20.207 +{
  20.208 +    //Annoyingly we can't just call into Java from any thread. Because the audio
  20.209 +    //callback is dispatched from the SDL audio thread (that wasn't made from
  20.210 +    //java, we have to do some magic here to let the JVM know about the thread.
  20.211 +    //Because everything it touches on the Java side is static anyway, it's 
  20.212 +    //not a big deal, just annoying.
  20.213 +    if(!mAudioThreadEnv) {
  20.214 +        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Need to set up audio thread env\n");
  20.215 +
  20.216 +        mVM->AttachCurrentThread(&mAudioThreadEnv, NULL);
  20.217 +
  20.218 +        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: ok\n");
  20.219 +    }
  20.220 +    
  20.221 +    jbyteArray arr = mAudioThreadEnv->NewByteArray(len);
  20.222 +
  20.223 +    //blah. We probably should rework this so we avoid the copy. 
  20.224 +    mAudioThreadEnv->SetByteArrayRegion(arr, 0, len, (jbyte *)buf);
  20.225 +    
  20.226 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: copied\n");
  20.227 +
  20.228 +    mAudioThreadEnv->CallStaticVoidMethod(  mActivityInstance, 
  20.229 +                                            midUpdateAudio, arr );
  20.230 +
  20.231 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: invoked\n");
  20.232 +    
  20.233 +}
  20.234 +
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/main/android/SDL_android_main.cpp	Thu Jan 06 16:11:21 2011 -0800
    21.3 @@ -0,0 +1,30 @@
    21.4 +
    21.5 +/* Include the SDL main definition header */
    21.6 +#include "SDL_main.h"
    21.7 +
    21.8 +/*******************************************************************************
    21.9 +                 Functions called by JNI
   21.10 +*******************************************************************************/
   21.11 +#include <jni.h>
   21.12 +
   21.13 +// Called before SDL_main() to initialize JNI bindings in SDL library
   21.14 +extern "C" void SDL_Android_Init(JNIEnv* env);
   21.15 +
   21.16 +// Library init
   21.17 +extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
   21.18 +{
   21.19 +    return JNI_VERSION_1_4;
   21.20 +}
   21.21 +
   21.22 +// Start up the SDL app
   21.23 +extern "C" void Java_org_libsdl_app_SDLActivity_nativeInit( JNIEnv* env, jobject obj )
   21.24 +{
   21.25 +    /* This interface could expand with ABI negotiation, calbacks, etc. */
   21.26 +    SDL_Android_Init(env);
   21.27 +
   21.28 +    /* Run the application code! */
   21.29 +    char *argv[2];
   21.30 +    argv[0] = strdup("SDL_app");
   21.31 +    argv[1] = NULL;
   21.32 +    SDL_main(1, argv);
   21.33 +}