- Added Android HelloWorld example. You must do following steps to run it:

1. Assign your Android SDK path to ANDROID_HOME environment variable.
2. Add Android SDK (ANDROID_HOME) and Android NDK to your PATH environment variable.
3. Go to: source->Irrlicht->Android and call "ndk-build" or "ndk-build NDEBUG=1"
4. Go to: examples->17.HelloWorld_Mobile and call "ndk-build" or "ndk-build NDEBUG=1"
5. Call "ant debug" to create package
6. Connect device to PC (with USB debugging mode ON) or turn on emulator.
7. Call "adb -d install bin/HelloWorldMobile-debug.apk" (if you use emulator please add "-e" parameter instead of "-d") to install package on your device/emulator.
8. That's all! Now you can run example.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@4528 dfc29bdd-3216-0410-991c-e03cc46cb475
master
nadro 2013-05-18 18:30:16 +00:00
parent 60aa1bb56e
commit a8b5d9f837
10 changed files with 347 additions and 234 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.irrlicht.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9"/>
<uses-feature android:glEsVersion="0x00010000" android:required="true"/>
<application android:icon="@drawable/irr_icon" android:label="HelloWorldMobile" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:debuggable="true">
<activity android:name="android.app.NativeActivity"
android:label="HelloWorldMobile"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true">
<meta-data android:name="android.app.lib_name" android:value="HelloWorldMobile" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorldMobile" default="help">
<property file="local.properties" />
<property file="ant.properties" />
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<loadproperties srcFile="project.properties" />
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<import file="custom_rules.xml" optional="true" />
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -0,0 +1,42 @@
LOCAL_PATH := $(call my-dir)/..
IRRLICHT_PROJECT_PATH := $(LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := HelloWorldMobile
LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_ -pipe -fno-exceptions -fno-rtti -fstrict-aliasing
ifndef NDEBUG
LOCAL_CFLAGS += -g -D_DEBUG
else
LOCAL_CFLAGS += -fexpensive-optimizations -O3
endif
ifeq ($(TARGET_ARCH_ABI),x86)
LOCAL_CFLAGS += -fno-stack-protector
endif
LOCAL_C_INCLUDES := ../../include
LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../lib/Android -lEGL -llog -lGLESv1_CM -lGLESv2 -lz -landroid -lIrrlicht
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
# copy Irrlicht data to assets
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets)
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets/media)
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets/media/Shaders)
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/src)
$(shell cp $(IRRLICHT_PROJECT_PATH)/../../media/Shaders/*.* $(IRRLICHT_PROJECT_PATH)/assets/media/Shaders/)
$(shell cp $(IRRLICHT_PROJECT_PATH)/../../media/irrlichtlogo3.png $(IRRLICHT_PROJECT_PATH)/assets/media/)
$(shell cp $(IRRLICHT_PROJECT_PATH)/../../media/sydney.md2 $(IRRLICHT_PROJECT_PATH)/assets/media/)
$(shell cp $(IRRLICHT_PROJECT_PATH)/../../media/sydney.bmp $(IRRLICHT_PROJECT_PATH)/assets/media/)

View File

@ -0,0 +1,2 @@
APP_PLATFORM := android-10
APP_MODULES := HelloWorldMobile

View File

@ -10,8 +10,10 @@
#ifdef _IRR_WINDOWS_
#include <windows.h>
#elif defined(_IRR_IPHONE_PLATFORM_)
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#elif defined(_IRR_ANDROID_PLATFORM_)
#include <android_native_app_glue.h>
#endif
using namespace irr;
@ -36,6 +38,7 @@ using namespace gui;
@end
#endif
#if !defined(_IRR_IPHONE_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
class EventReceiver_basic : public IEventReceiver
{
private:
@ -64,211 +67,6 @@ public:
}
};
class CSampleSceneNode : public ISceneNode
{
aabbox3d<f32> Box;
S3DVertex Vertices[4];
SMaterial Material;
public:
CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id)
: ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = false;
Vertices[0] = S3DVertex(0,0,10, 1,1,0, SColor(255,0,255,255), 0, 1);
Vertices[1] = S3DVertex(10,0,-10, 1,0,0, SColor(255,255,0,255), 1, 1);
Vertices[2] = S3DVertex(0,20,0, 0,1,1, SColor(255,255,255,0), 1, 0);
Vertices[3] = S3DVertex(-10,0,-10, 0,0,1, SColor(255,0,255,0), 0, 0);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
virtual void OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
virtual void render()
{
u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 };
IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4);
}
virtual const aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual u32 getMaterialCount()
{
return 1;
}
virtual SMaterial& getMaterial(u32 i)
{
return Material;
}
};
/*!
Startup a Windows Mobile Device
*/
IrrlichtDevice *startup()
{
// create device
IrrlichtDevice *device = 0;
#ifdef _IRR_IPHONE_PLATFORM_
AppDelegate* delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
SIrrlichtCreationParameters param;
param.DriverType = EDT_OGLES2;
param.WindowSize = dimension2d<u32>(0,0);
param.WindowId = delegate.window;
param.Bits = 24;
param.ZBufferBits = 16;
param.AntiAlias = 0;
device = createDeviceEx(param);
#elif defined(_IRR_USE_WINDOWS_CE_DEVICE_)
// set to standard mobile fullscreen 240x320
device = createDevice(EDT_OPENGL, dimension2d<u32>(240, 320), 16, true );
#else
// on PC. use window mode
device = createDevice(EDT_OPENGL, dimension2d<u32>(240, 320), 16, false );
#endif
if ( 0 == device )
return 0;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
#ifdef _IRR_IPHONE_PLATFORM_
stringc mediaPath = "media/";
#else
stringc mediaPath = "../../media/";
#endif
// set the filesystem relative to the executable
#if defined (_IRR_WINDOWS_)
{
wchar_t buf[255];
GetModuleFileNameW ( 0, buf, 255 );
io::path base = buf;
base = base.subString ( 0, base.findLast ( '\\' ) + 1 );
device->getFileSystem()->addFileArchive ( base );
}
#endif
IGUIStaticText *text = guienv->addStaticText(L"FPS: 25",
rect<s32>(140,15,200,30), false, false, 0, 100 );
#ifndef _IRR_IPHONE_PLATFORM_
// programmable quit button isn't allowed on iOS.
guienv->addButton(core::rect<int>(200,10,238,30), 0, 2, L"Quit");
#endif
// add irrlicht logo
guienv->addImage(driver->getTexture(mediaPath + "irrlichtlogo3.png"),
core::position2d<s32>(0,-2));
return device;
}
/*!
*/
int run ( IrrlichtDevice *device )
{
#ifdef _IRR_IPHONE_PLATFORM_
while (device)
{
NSAutoreleasePool* tPool = [[NSAutoreleasePool alloc] init];
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.002f, TRUE) == kCFRunLoopRunHandledSource);
[tPool release];
if(device->run())
#else
while(device->run())
if (device->isWindowActive())
#endif
{
device->getVideoDriver()->beginScene(true, true, SColor(0,100,100,100));
device->getSceneManager()->drawAll();
device->getGUIEnvironment()->drawAll();
device->getVideoDriver()->endScene ();
IGUIElement *stat = device->getGUIEnvironment()->
getRootGUIElement()->getElementFromId ( 100 );
if ( stat )
{
stringw str = L"FPS: ";
str += (s32)device->getVideoDriver()->getFPS();
stat->setText ( str.c_str() );
}
}
#ifndef _IRR_IPHONE_PLATFORM_
device->drop();
#else
else
break;
}
#endif
return 1;
}
/*!
*/
int example_customscenenode()
{
// create device
IrrlichtDevice *device = startup();
if (device == 0)
return 1; // could not create selected driver.
// create engine and camera
EventReceiver_basic receiver(device);
device->setEventReceiver(&receiver);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
smgr->addCameraSceneNode(0, vector3df(0,-40,0), vector3df(0,0,0));
CSampleSceneNode *myNode =
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
ISceneNodeAnimator* anim =
smgr->createRotationAnimator(vector3df(0.8f, 0, 0.8f));
if(anim)
{
myNode->addAnimator(anim);
anim->drop();
anim = 0; // As I shouldn't refer to it again, ensure that I can't
}
myNode->drop();
myNode = 0; // As I shouldn't refer to it again, ensure that I can't
return run ( device );
}
class EventReceiver_terrain : public IEventReceiver
{
public:
@ -338,11 +136,222 @@ private:
bool showBox;
};
class CSampleSceneNode : public ISceneNode
{
aabbox3d<f32> Box;
S3DVertex Vertices[4];
SMaterial Material;
public:
/*
The start of the main function starts like in most other example. We ask the user
for the desired renderer and start it up. This time with the advanced parameter handling.
CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id)
: ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = false;
Vertices[0] = S3DVertex(0,0,10, 1,1,0, SColor(255,0,255,255), 0, 1);
Vertices[1] = S3DVertex(10,0,-10, 1,0,0, SColor(255,255,0,255), 1, 1);
Vertices[2] = S3DVertex(0,20,0, 0,1,1, SColor(255,255,255,0), 1, 0);
Vertices[3] = S3DVertex(-10,0,-10, 0,0,1, SColor(255,0,255,0), 0, 0);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
virtual void OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
virtual void render()
{
u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 };
IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4);
}
virtual const aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual u32 getMaterialCount()
{
return 1;
}
virtual SMaterial& getMaterial(u32 i)
{
return Material;
}
};
#endif
#ifdef _IRR_ANDROID_PLATFORM_
IrrlichtDevice *startup(android_app* app)
#else
IrrlichtDevice *startup()
#endif
{
// create device
IrrlichtDevice *device = 0;
#ifdef _IRR_IPHONE_PLATFORM_
AppDelegate* delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
SIrrlichtCreationParameters param;
param.DriverType = EDT_OGLES2;
param.WindowSize = dimension2d<u32>(0,0);
param.WindowId = delegate.window;
param.Bits = 24;
param.ZBufferBits = 16;
param.AntiAlias = 0;
device = createDeviceEx(param);
#elif defined(_IRR_ANDROID_PLATFORM_)
SIrrlichtCreationParameters param;
param.DriverType = EDT_OGLES2;
param.WindowSize = dimension2d<u32>(480,854);
param.PrivateData = app;
param.Bits = 24;
param.ZBufferBits = 16;
param.AntiAlias = 0;
device = createDeviceEx(param);
#elif defined(_IRR_USE_WINDOWS_CE_DEVICE_)
// set to standard mobile fullscreen 240x320
device = createDevice(EDT_OPENGL, dimension2d<u32>(240, 320), 16, true);
#else
// on PC. use window mode
device = createDevice(EDT_OPENGL, dimension2d<u32>(240, 320), 16, false);
#endif
if (!device)
return 0;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
#if defined(_IRR_IPHONE_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_)
stringc mediaPath = "media/";
#else
stringc mediaPath = "../../media/";
#endif
// set the filesystem relative to the executable
#if defined (_IRR_WINDOWS_)
{
wchar_t buf[255];
GetModuleFileNameW ( 0, buf, 255 );
io::path base = buf;
base = base.subString ( 0, base.findLast ( '\\' ) + 1 );
device->getFileSystem()->addFileArchive ( base );
}
#endif
IGUIStaticText *text = guienv->addStaticText(L"FPS: 25",
rect<s32>(140,15,200,30), false, false, 0, 100 );
#if !defined(_IRR_IPHONE_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
// programmable quit button isn't allowed on iOS.
guienv->addButton(core::rect<int>(200,10,238,30), 0, 2, L"Quit");
#endif
// add irrlicht logo
guienv->addImage(driver->getTexture(mediaPath + "irrlichtlogo3.png"),
core::position2d<s32>(0,-2));
return device;
}
/*!
*/
int run ( IrrlichtDevice *device )
{
#ifdef _IRR_IPHONE_PLATFORM_
while (device)
{
NSAutoreleasePool* tPool = [[NSAutoreleasePool alloc] init];
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.002f, TRUE) == kCFRunLoopRunHandledSource);
[tPool release];
if(device->run())
#else
while(device->run())
if (device->isWindowActive())
#endif
{
device->getVideoDriver()->beginScene(true, true, SColor(0,100,100,100));
device->getSceneManager()->drawAll();
device->getGUIEnvironment()->drawAll();
device->getVideoDriver()->endScene ();
IGUIElement *stat = device->getGUIEnvironment()->
getRootGUIElement()->getElementFromId ( 100 );
if ( stat )
{
stringw str = L"FPS: ";
str += (s32)device->getVideoDriver()->getFPS();
stat->setText ( str.c_str() );
}
}
#ifndef _IRR_IPHONE_PLATFORM_
device->drop();
#else
else
break;
}
#endif
return 1;
}
#if !defined(_IRR_IPHONE_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
int example_customscenenode()
{
// create device
IrrlichtDevice *device = startup();
if (device == 0)
return 1; // could not create selected driver.
// create engine and camera
EventReceiver_basic receiver(device);
device->setEventReceiver(&receiver);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
smgr->addCameraSceneNode(0, vector3df(0,-40,0), vector3df(0,0,0));
CSampleSceneNode *myNode =
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
ISceneNodeAnimator* anim =
smgr->createRotationAnimator(vector3df(0.8f, 0, 0.8f));
if(anim)
{
myNode->addAnimator(anim);
anim->drop();
anim = 0; // As I shouldn't refer to it again, ensure that I can't
}
myNode->drop();
myNode = 0; // As I shouldn't refer to it again, ensure that I can't
return run ( device );
}
int example_terrain()
{
// create device
@ -485,44 +494,52 @@ int example_terrain()
return run ( device );
}
#endif
/*
*/
#ifdef _IRR_IPHONE_PLATFORM_
IrrlichtDevice* example_helloworld()
#elif defined(_IRR_ANDROID_PLATFORM_)
int example_helloworld(android_app* app)
#else
int example_helloworld()
#endif
{
// create device
#ifdef _IRR_ANDROID_PLATFORM_
IrrlichtDevice *device = startup(app);
#else
IrrlichtDevice *device = startup();
#endif
if (device == 0)
#ifdef _IRR_IPHONE_PLATFORM_
return 0;
#else
return 1
#endif
#ifdef _IRR_IPHONE_PLATFORM_
return 0;
#else
return 1;
#endif
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
#ifdef _IRR_IPHONE_PLATFORM_
stringc mediaPath = "media/";
#if defined(_IRR_IPHONE_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_)
stringc mediaPath = "media/";
#else
stringc mediaPath = "../../media/";
stringc mediaPath = "../../media/";
#endif
IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "sydney.md2");
if (!mesh)
{
device->drop();
#ifdef _IRR_IPHONE_PLATFORM_
return 0;
#else
return 1
#endif
#ifdef _IRR_IPHONE_PLATFORM_
return 0;
#else
return 1;
#endif
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
/*
@ -548,9 +565,14 @@ int example_helloworld()
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
#ifdef _IRR_IPHONE_PLATFORM_
return device;
return device;
#elif defined(_IRR_ANDROID_PLATFORM_)
run(device);
device->drop();
return 0;
#else
EventReceiver_basic receiver(device);
EventReceiver_basic receiver(device);
device->setEventReceiver(&receiver);
return run ( device );
@ -626,20 +648,27 @@ int example_helloworld()
@end
#endif
#ifndef _IRR_ANDROID_PLATFORM_
int main(int argc, char *argv[])
#else
void android_main(android_app* app)
#endif
{
#ifdef _IRR_IPHONE_PLATFORM_
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
[pool release];
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
[pool release];
return retVal;
return retVal;
#elif defined(_IRR_ANDROID_PLATFORM_)
app_dummy();
example_helloworld(app);
#else
example_helloworld ();
example_helloworld();
example_customscenenode();
//example_terrain();
return 0;
#endif
}
/*
**/

View File

@ -0,0 +1 @@
target = android-10

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB