Click here to Skip to main content
15,615,280 members
Articles / Mobile Apps / Android
Technical Blog
Posted 21 Feb 2012

Tagged as


5 bookmarked

Wrapping Irrlicht For Android

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
21 Feb 2012CPOL2 min read
Irrlicht is a well-known Open Source 3D engine, which supports multiple platforms

Irrlicht is a well-known Open Source 3D engine, which supports multiple platforms. It has been ported to Android by Laurent Mallet, the source code can be obtained from here. The code is written in C++, but Android mainly supports Java. Using native C++ on Android to develop applications is more difficult, and not convenient, especially to debug. For a developer to use irrlicht easily, it is best to provide Java interfaces.

The work here is wrapping irrlicht engine to enable it to provide the Java interface. Traditional method for Java calling native code is using the jni mechanism. But irrlicht engine is big and has many render objects. Using jni directly to wrap irrlicht will be a hard work. We have to define classes in Java, create C++ code skeleton, maintain global reference of Java object to irrlicht render object, process callback, etc. In order to simplify programming, CLE is used as middleware to help Java to call native code.

CLE (Common Language Extension) is developed by srplab, which presents a general method for mixed language calls. It supports distributed object technique, which objects as medium to implement the mixed call between languages. Programming with cle, you need not care about details of special script languages, and the wrapping supports many languages such as Java, Lua, Python, etc.

Wrapping irrlicht with cle, the first step is to create interface description using XML language, as follows:

<?xml version="1.0" encoding="utf-8" ?>
<service ID="d52a1620-6a1c-401b-9c31-826793086683" 
Password="123" Name="SRPIrrlichtES2Engine">
<SRPFSEngine />
<SRPIrrlichtES2EngineBasicModule ID="73e4254e-1fed-4d15-970a-0756a39521ea" />
<SRP3DVector ID="e41ba4f5-ef8f-477d-9c03-dafe387f04f9">
<X Type="VS_FLOAT" />
<Y Type="VS_FLOAT" />
<Z Type="VS_FLOAT" />
<BasicServiceItem ID="66d95cfa-ab44-481c-af86-101339687bf0" 
<IrrDeviceClass ID="bb11872b-ae5e-45b7-8fd6-a0d009d1bb5d" SysEvent="true">
<Color Type="VS_COLOR" Default="" EditType="3" />
<Width Type="VS_INT32" Default="800" />
<Height Type="VS_INT32" Default="600" />
<RenderWnd Type="VS_ULONG" SyncFlag="1" Default="" />
<GetCurDevice ID="fb76adbd-13ec-423b-a7ea-f8434bf6823c">
<output Type="void *" />
<Lua_GetCurDevice Type="luafunc" Desc="Driver=Lua_GetCurDevice()" 
ID="28d4732e-e36e-434a-a838-b9b29f17dc1a" />

The above XML description can also be created using tools srpdebug, which can be downloaded from srplab web site. After finishing the description, uses srpdebug tool or star2c command line tool to create C/C++ code skeleton.

Each object will be associated with one or more irrlicht objects. For the above “IrrDeviceClass”, when activated, an irrlicht device object will be created, as follows:


//TriggerForLoadFlag = LocalEventParaPtr -> RequestParam -> LParam;
IrrlichtDeviceClassLocalBuf = (struct StructOfIrrlichtDeviceClassLocalBuf *)pSRP -> 
                               GetPrivateBuf( IrrDeviceClassPtr, IrrlichtDeviceClass_ClassLayer,
                               IRRLICHTDEVICECLASS_LOCALVARINDEX, NULL );
if( IrrlichtDeviceClassLocalBuf -> SRPEventReceiver == NULL )
IrrlichtDeviceClassLocalBuf -> SRPEventReceiver = new class ClassOfSRPEventReceiver();
if( IrrlichtDeviceClassLocalBuf ->IrrlichtDevice == NULL ){
irr::SIrrlichtCreationParameters param; 

param.DriverType = video::EDT_OGLES2;
param.WindowId = (void *)IrrDeviceClassPtr ->RenderWnd;
param.WindowSize = core::dimension2d<s32>
(IrrDeviceClassPtr->Width, IrrDeviceClassPtr->Height);
param.Bits = 16;
param.Fullscreen = false;
param.Stencilbuffer = false;
param.Vsync = false;
param.AntiAlias = false;
param.HighPrecisionFPU = false;
param.EventReceiver = IrrlichtDeviceClassLocalBuf -> SRPEventReceiver;
IrrlichtDeviceClassLocalBuf ->IrrlichtDevice = irr::createDeviceEx(param);
_control87( _MCW_EM,0x801f );
pSRP ->GetID(IrrDeviceClassPtr,&g_DeviceObjectID);

Finish the C++ code, create project to generate SRPIrrlichtES2EngineBasicModule.dll for Windows, or for Android.

For Java, to call the above library, the code is as follows:

starcore= StarCoreFactory.GetFactory(); 
SrvGroup = (StarSrvGroupClass)Service._Get("_ServiceGroup");

When Device._Active() is called, the C++ event VSEVENT_SYSTEMEVENT_ONACTIVATE will be generated, then the corresponding irrlicht device is created.

An example Helloworld:

The wrapping work is in progress, you can download the full source code from

This article was originally posted at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

-- There are no messages in this forum --