Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added minimal test project
Browse files Browse the repository at this point in the history
  • Loading branch information
bieh committed Jun 17, 2010
1 parent 6153328 commit 6771f38
Show file tree
Hide file tree
Showing 16 changed files with 648 additions and 0 deletions.
15 changes: 15 additions & 0 deletions android/testproject/AndroidManifest.xml
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.libsdl.android"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="TestActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
17 changes: 17 additions & 0 deletions android/testproject/build.properties
@@ -0,0 +1,17 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked in Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

67 changes: 67 additions & 0 deletions android/testproject/build.xml
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Test" default="help">

<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked in in Version
Control Systems. -->
<property file="local.properties" />

<!-- The build.properties file can be created by you and is never touched
by the 'android' tool. This is the place to change some of the default property values
used by the Ant rules.
Here are some properties you may want to change/update:
application.package
the name of your application package as defined in the manifest. Used by the
'uninstall' rule.
source.dir
the name of the source directory. Default is 'src'.
out.dir
the name of the output directory. Default is 'bin'.
Properties related to the SDK location or the project target should be updated
using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your application and
should be checked in in Version Control Systems.
-->
<property file="build.properties" />

<!-- The default.properties file is created and updated by the 'android' tool, as well
as ADT.
This file is an integral part of the build system for your application and
should be checked in in Version Control Systems. -->
<property file="default.properties" />

<!-- Custom Android task to deal with the project target, and import the proper rules.
This requires ant 1.6.0 or above. -->
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
<pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
<pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
<pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
<pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
</path>

<taskdef name="setup"
classname="com.android.ant.SetupTask"
classpathref="android.antlibs" />

<!-- Execute the Android Setup task that will setup some properties specific to the target,
and import the build rules files.
The rules file is imported from
<SDK>/platforms/<target_platform>/templates/android_rules.xml
To customize some build steps for your project:
- copy the content of the main node <project> from android_rules.xml
- paste it in this build.xml below the <setup /> task.
- disable the import by changing the setup task below to <setup import="false" />
This will ensure that the properties are setup correctly but that your customized
build steps are used.
-->
<setup />

</project>
11 changes: 11 additions & 0 deletions android/testproject/default.properties
@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=Google Inc.:Google APIs:7
16 changes: 16 additions & 0 deletions android/testproject/jni/Android.mk
@@ -0,0 +1,16 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := sanangeles

LOCAL_CFLAGS := -DANDROID_NDK \
-DDISABLE_IMPORTGL

LOCAL_SRC_FILES := \
importgl.c \
app-android.c \

LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog

include $(BUILD_SHARED_LIBRARY)
79 changes: 79 additions & 0 deletions android/testproject/jni/app-android.c
@@ -0,0 +1,79 @@
/*******************************************************************************
Headers
*******************************************************************************/
#include <jni.h>
#include <sys/time.h>
#include <time.h>
#include <android/log.h>
#include <stdint.h>

/*******************************************************************************
Globals
*******************************************************************************/
int gAppAlive = 1;

static int sWindowWidth = 320;
static int sWindowHeight = 480;
static int sDemoStopped = 0;

static long _getTime(void){
struct timeval now;
gettimeofday(&now, NULL);
return (long)(now.tv_sec*1000 + now.tv_usec/1000);
}

/*******************************************************************************
Initialize the graphics state
*******************************************************************************/
void Java_org_libsdl_android_TestRenderer_nativeInit( JNIEnv* env )
{
importGLInit();

gAppAlive = 1;
sDemoStopped = 0;
}

/*******************************************************************************
Resize
*******************************************************************************/
void Java_org_libsdl_android_TestRenderer_nativeResize( JNIEnv* env,
jobject thiz,
jint w,
jint h )
{
sWindowWidth = w;
sWindowHeight = h;
__android_log_print(ANDROID_LOG_INFO, "SDL", "resize w=%d h=%d", w, h);
}

/*******************************************************************************
Finalize (ie: shutdown)
*******************************************************************************/
void Java_org_libsdl_android_TestRenderer_nativeDone( JNIEnv* env )
{

//shut down the app

importGLDeinit();
}

/*******************************************************************************
Pause (ie: stop as soon as possible)
*******************************************************************************/
void Java_org_libsdl_android_TestGLSurfaceView_nativePause( JNIEnv* env )
{
sDemoStopped = !sDemoStopped;
if (sDemoStopped) {
//we paused
} else {
//we resumed
}
}

/*******************************************************************************
Render the next frame
*******************************************************************************/
void Java_org_libsdl_android_TestRenderer_nativeRender( JNIEnv* env )
{
//TODO: Render here
}
168 changes: 168 additions & 0 deletions android/testproject/jni/importgl.c
@@ -0,0 +1,168 @@
/* San Angeles Observation OpenGL ES version example
* Copyright 2004-2005 Jetro Lauha
* All rights reserved.
* Web: http://iki.fi/jetro/
*
* This source is free software; you can redistribute it and/or
* modify it under the terms of EITHER:
* (1) The GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at
* your option) any later version. The text of the GNU Lesser
* General Public License is included with this source in the
* file LICENSE-LGPL.txt.
* (2) The BSD-style license that is included with this source in
* the file LICENSE-BSD.txt.
*
* This source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
* LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
*
* $Id: importgl.c,v 1.4 2005/02/08 18:42:55 tonic Exp $
* $Revision: 1.4 $
*/

#undef WIN32
#undef LINUX
#ifdef _MSC_VER
// Desktop or mobile Win32 environment:
#define WIN32
#else
// Linux environment:
#define LINUX
#endif

#ifndef DISABLE_IMPORTGL

#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
static HMODULE sGLESDLL = NULL;
#endif // WIN32

#ifdef LINUX
#include <stdlib.h>
#include <dlfcn.h>
static void *sGLESSO = NULL;
#endif // LINUX

#endif /* DISABLE_IMPORTGL */

#define IMPORTGL_NO_FNPTR_DEFS
#define IMPORTGL_API
#define IMPORTGL_FNPTRINIT = NULL
#include "importgl.h"


/* Imports function pointers to selected function calls in OpenGL ES Common
* or Common Lite profile DLL or shared object. The function pointers are
* stored as global symbols with equivalent function name but prefixed with
* "funcPtr_". Standard gl/egl calls are redirected to the function pointers
* with preprocessor macros (see importgl.h).
*/
int importGLInit()
{
int result = 1;

#ifndef DISABLE_IMPORTGL

#undef IMPORT_FUNC

#ifdef WIN32
sGLESDLL = LoadLibrary(_T("libGLES_CM.dll"));
if (sGLESDLL == NULL)
sGLESDLL = LoadLibrary(_T("libGLES_CL.dll"));
if (sGLESDLL == NULL)
return 0; // Cannot find OpenGL ES Common or Common Lite DLL.

/* The following fetches address to each egl & gl function call
* and stores it to the related function pointer. Casting through
* void * results in warnings with VC warning level 4, which
* could be fixed by casting to the true type for each fetch.
*/
#define IMPORT_FUNC(funcName) do { \
void *procAddress = (void *)GetProcAddress(sGLESDLL, _T(#funcName)); \
if (procAddress == NULL) result = 0; \
*((void **)&FNPTR(funcName)) = procAddress; } while (0)
#endif // WIN32

#ifdef LINUX
#ifdef ANDROID_NDK
sGLESSO = dlopen("libGLESv1_CM.so", RTLD_NOW);
#else /* !ANDROID_NDK */
sGLESSO = dlopen("libGLES_CM.so", RTLD_NOW);
if (sGLESSO == NULL)
sGLESSO = dlopen("libGLES_CL.so", RTLD_NOW);
#endif /* !ANDROID_NDK */
if (sGLESSO == NULL)
return 0; // Cannot find OpenGL ES Common or Common Lite SO.

#define IMPORT_FUNC(funcName) do { \
void *procAddress = (void *)dlsym(sGLESSO, #funcName); \
if (procAddress == NULL) result = 0; \
*((void **)&FNPTR(funcName)) = procAddress; } while (0)
#endif // LINUX

#ifndef ANDROID_NDK
IMPORT_FUNC(eglChooseConfig);
IMPORT_FUNC(eglCreateContext);
IMPORT_FUNC(eglCreateWindowSurface);
IMPORT_FUNC(eglDestroyContext);
IMPORT_FUNC(eglDestroySurface);
IMPORT_FUNC(eglGetConfigAttrib);
IMPORT_FUNC(eglGetConfigs);
IMPORT_FUNC(eglGetDisplay);
IMPORT_FUNC(eglGetError);
IMPORT_FUNC(eglInitialize);
IMPORT_FUNC(eglMakeCurrent);
IMPORT_FUNC(eglSwapBuffers);
IMPORT_FUNC(eglTerminate);
#endif /* !ANDROID_NDK */

IMPORT_FUNC(glBlendFunc);
IMPORT_FUNC(glClear);
IMPORT_FUNC(glClearColorx);
IMPORT_FUNC(glColor4x);
IMPORT_FUNC(glColorPointer);
IMPORT_FUNC(glDisable);
IMPORT_FUNC(glDisableClientState);
IMPORT_FUNC(glDrawArrays);
IMPORT_FUNC(glEnable);
IMPORT_FUNC(glEnableClientState);
IMPORT_FUNC(glFrustumx);
IMPORT_FUNC(glGetError);
IMPORT_FUNC(glLightxv);
IMPORT_FUNC(glLoadIdentity);
IMPORT_FUNC(glMaterialx);
IMPORT_FUNC(glMaterialxv);
IMPORT_FUNC(glMatrixMode);
IMPORT_FUNC(glMultMatrixx);
IMPORT_FUNC(glNormalPointer);
IMPORT_FUNC(glPopMatrix);
IMPORT_FUNC(glPushMatrix);
IMPORT_FUNC(glRotatex);
IMPORT_FUNC(glScalex);
IMPORT_FUNC(glShadeModel);
IMPORT_FUNC(glTranslatex);
IMPORT_FUNC(glVertexPointer);
IMPORT_FUNC(glViewport);

#endif /* DISABLE_IMPORTGL */

return result;
}


void importGLDeinit()
{
#ifndef DISABLE_IMPORTGL
#ifdef WIN32
FreeLibrary(sGLESDLL);
#endif

#ifdef LINUX
dlclose(sGLESSO);
#endif
#endif /* DISABLE_IMPORTGL */
}

0 comments on commit 6771f38

Please sign in to comment.