Move Android example into it's own example folder.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@4652 dfc29bdd-3216-0410-991c-e03cc46cb475master
|
@ -12,8 +12,6 @@
|
|||
#elif defined(_IRR_IPHONE_PLATFORM_)
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#elif defined(_IRR_ANDROID_PLATFORM_)
|
||||
#include <android_native_app_glue.h>
|
||||
#endif
|
||||
|
||||
using namespace irr;
|
||||
|
@ -38,7 +36,7 @@ using namespace gui;
|
|||
@end
|
||||
#endif
|
||||
|
||||
#if !defined(_IRR_IPHONE_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
|
||||
#if !defined(_IRR_IPHONE_PLATFORM_)
|
||||
class EventReceiver_basic : public IEventReceiver
|
||||
{
|
||||
private:
|
||||
|
@ -192,11 +190,7 @@ public:
|
|||
};
|
||||
#endif
|
||||
|
||||
#ifdef _IRR_ANDROID_PLATFORM_
|
||||
IrrlichtDevice *startup(android_app* app)
|
||||
#else
|
||||
IrrlichtDevice *startup()
|
||||
#endif
|
||||
{
|
||||
// create device
|
||||
IrrlichtDevice *device = 0;
|
||||
|
@ -213,16 +207,6 @@ IrrlichtDevice *startup()
|
|||
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);
|
||||
|
@ -237,7 +221,7 @@ IrrlichtDevice *startup()
|
|||
ISceneManager* smgr = device->getSceneManager();
|
||||
IGUIEnvironment* guienv = device->getGUIEnvironment();
|
||||
|
||||
#if defined(_IRR_IPHONE_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_)
|
||||
#if defined(_IRR_IPHONE_PLATFORM_)
|
||||
stringc mediaPath = "media/";
|
||||
#else
|
||||
stringc mediaPath = "../../media/";
|
||||
|
@ -259,7 +243,7 @@ IrrlichtDevice *startup()
|
|||
rect<s32>(140,15,200,30), false, false, 0, 100 );
|
||||
|
||||
|
||||
#if !defined(_IRR_IPHONE_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
|
||||
#if !defined(_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
|
||||
|
@ -314,7 +298,7 @@ int run ( IrrlichtDevice *device )
|
|||
return 1;
|
||||
}
|
||||
|
||||
#if !defined(_IRR_IPHONE_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
|
||||
#if !defined(_IRR_IPHONE_PLATFORM_)
|
||||
int example_customscenenode()
|
||||
{
|
||||
// create device
|
||||
|
@ -498,18 +482,12 @@ int example_terrain()
|
|||
|
||||
#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_
|
||||
|
@ -522,7 +500,7 @@ int example_helloworld()
|
|||
ISceneManager* smgr = device->getSceneManager();
|
||||
IGUIEnvironment* guienv = device->getGUIEnvironment();
|
||||
|
||||
#if defined(_IRR_IPHONE_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_)
|
||||
#if defined(_IRR_IPHONE_PLATFORM_)
|
||||
stringc mediaPath = "media/";
|
||||
#else
|
||||
stringc mediaPath = "../../media/";
|
||||
|
@ -566,11 +544,6 @@ int example_helloworld()
|
|||
|
||||
#ifdef _IRR_IPHONE_PLATFORM_
|
||||
return device;
|
||||
#elif defined(_IRR_ANDROID_PLATFORM_)
|
||||
run(device);
|
||||
device->drop();
|
||||
|
||||
return 0;
|
||||
#else
|
||||
EventReceiver_basic receiver(device);
|
||||
device->setEventReceiver(&receiver);
|
||||
|
@ -648,11 +621,7 @@ 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];
|
||||
|
@ -660,9 +629,6 @@ void android_main(android_app* app)
|
|||
[pool release];
|
||||
|
||||
return retVal;
|
||||
#elif defined(_IRR_ANDROID_PLATFORM_)
|
||||
app_dummy();
|
||||
example_helloworld(app);
|
||||
#else
|
||||
example_helloworld();
|
||||
example_customscenenode();
|
||||
|
@ -671,4 +637,3 @@ void android_main(android_app* app)
|
|||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
/** Example 27 Helloworld_Android
|
||||
This example shows Hello World for Android.
|
||||
You need a GUI, because otherwise you can't quit the application.
|
||||
You need a Filesystem, which is relative based to your executable.
|
||||
*/
|
||||
|
||||
#include <irrlicht.h>
|
||||
|
||||
#ifdef _IRR_ANDROID_PLATFORM_
|
||||
|
||||
#include <android_native_app_glue.h>
|
||||
|
||||
using namespace irr;
|
||||
using namespace core;
|
||||
using namespace scene;
|
||||
using namespace video;
|
||||
using namespace io;
|
||||
using namespace gui;
|
||||
|
||||
#pragma comment(lib, "Irrlicht.lib")
|
||||
|
||||
|
||||
enum GUI_IDS
|
||||
{
|
||||
GUI_INFO_FPS = 100
|
||||
};
|
||||
|
||||
IrrlichtDevice *startup(android_app* app)
|
||||
{
|
||||
// create device
|
||||
IrrlichtDevice *device = 0;
|
||||
|
||||
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);
|
||||
if (!device)
|
||||
return 0;
|
||||
|
||||
IVideoDriver* driver = device->getVideoDriver();
|
||||
ISceneManager* smgr = device->getSceneManager();
|
||||
IGUIEnvironment* guienv = device->getGUIEnvironment();
|
||||
|
||||
stringc mediaPath = "media/";
|
||||
|
||||
IGUIStaticText *text = guienv->addStaticText(L"FPS: 25",
|
||||
rect<s32>(140,15,200,30), false, false, 0, GUI_INFO_FPS );
|
||||
|
||||
// add irrlicht logo
|
||||
guienv->addImage(driver->getTexture(mediaPath + "irrlichtlogo3.png"),
|
||||
core::position2d<s32>(0,-2));
|
||||
return device;
|
||||
}
|
||||
|
||||
/*! mainloop
|
||||
*/
|
||||
int run ( IrrlichtDevice *device )
|
||||
{
|
||||
while(device->run())
|
||||
{
|
||||
if (device->isWindowActive())
|
||||
{
|
||||
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 ( GUI_INFO_FPS );
|
||||
if ( stat )
|
||||
{
|
||||
stringw str = L"FPS: ";
|
||||
str += (s32)device->getVideoDriver()->getFPS();
|
||||
|
||||
stat->setText ( str.c_str() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
device->drop();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int example_helloworld(android_app* app)
|
||||
{
|
||||
// create device
|
||||
IrrlichtDevice *device = startup(app);
|
||||
|
||||
if (device == 0)
|
||||
return 1;
|
||||
|
||||
IVideoDriver* driver = device->getVideoDriver();
|
||||
ISceneManager* smgr = device->getSceneManager();
|
||||
IGUIEnvironment* guienv = device->getGUIEnvironment();
|
||||
|
||||
stringc mediaPath = "media/";
|
||||
|
||||
IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "sydney.md2");
|
||||
|
||||
if (!mesh)
|
||||
{
|
||||
device->drop();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
To let the mesh look a little bit nicer, we change its material. We
|
||||
disable lighting because we do not have a dynamic light in here, and
|
||||
the mesh would be totally black otherwise. Then we set the frame loop,
|
||||
such that the predefined STAND animation is used. And last, we apply a
|
||||
texture to the mesh. Without it the mesh would be drawn using only a
|
||||
color.
|
||||
*/
|
||||
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
|
||||
if (node)
|
||||
{
|
||||
node->setMaterialFlag(EMF_LIGHTING, false);
|
||||
node->setMD2Animation(scene::EMAT_STAND);
|
||||
node->setMaterialTexture( 0, driver->getTexture(mediaPath + "sydney.bmp") );
|
||||
}
|
||||
|
||||
/*
|
||||
To look at the mesh, we place a camera into 3d space at the position
|
||||
(0, 30, -40). The camera looks from there to (0,5,0), which is
|
||||
approximately the place where our md2 model is.
|
||||
*/
|
||||
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
|
||||
|
||||
run(device);
|
||||
device->drop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void android_main(android_app* app)
|
||||
{
|
||||
// Make sure glue isn't stripped.
|
||||
app_dummy();
|
||||
|
||||
example_helloworld(app);
|
||||
}
|
||||
|
||||
#endif // defined(_IRR_ANDROID_PLATFORM_)
|
|
@ -0,0 +1,18 @@
|
|||
To use Android you need to have installed:
|
||||
- Android SDK (from http://developer.android.com)
|
||||
- Android NDK (from http://developer.android.com)
|
||||
- ant (a build tool commonly used for Java)
|
||||
- A Java jdk (for example openjdk-6-jdk)
|
||||
|
||||
1. Assign your Android SDK path to an ANDROID_HOME environment variable.
|
||||
2. Add $ANDROID_HOME/tools and $ANDROID_HOME/platform-tools and the Android NDK main folder to your PATH environment variable.
|
||||
3. Go to: source->Irrlicht->Android and call "ndk-build" or "ndk-build NDEBUG=1"
|
||||
4. Go to: examples->27.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.
|
||||
|
||||
Troubleshooting:
|
||||
|
||||
Error: Unable to resolve project target 'android-10'
|
||||
Solution: Run "android sdk" in sdk/tools and install API 10
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |