Native Android port

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Native Android port

Post by Nadro »

I fixed it, before compilation make sure that somewhere at first lines of "include/irrCompileConfig.h" (eg. at line 47) you added "#define _IRR_ANDROID_PLATFORM_". When this variable is defined both OGLES1 and OGLES2 drivers are compiled (you can change it at lines 111 and 112).

OGLES1 driver is currently in stable state (I use it eg. in my iOS games), OGLES2 is under development (this is my priority now), but if You don't need fixed pipeline stuff and parallax/normal mapping materials built-in Irrlicht this driver should works good for you.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Native Android port

Post by mazataza »

thanks alot.
I could compile and I got *.a files.
but you can tell me how to build shared library which i can use it in my android application without recompiling every thing each time?
what i realy want is to have GLSurfaceView on which i use irrlicht to do 3D stuf, so irrlicht will not run inside an native activity.
I mix java code with native code.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Native Android port

Post by Nadro »

I tried with Hiker to create shared library some time ago, but we had problem with that (some native Android code was removed and/or package didn't accept two *.so files). Maybe with the latest SDK and NDK it will be working ok, but I don't know. I'm not too much experience with Android platform, so currently I can't help in this case. If You have static library You don't have to recompile it each time, just link them.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Native Android port

Post by mazataza »

aha.
I will try an example which run irrlich inside an GLSurface without native activity.
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Native Android port

Post by mazataza »

I got to compile the an example code.
but the application is exit without any errors (I think it is a segmentation fault).

I think it is because i tried to call this code from my GLSurface Render to initialize Irrlich

Code: Select all

 
void Java_com_amazweb_irrilichexample_NativeGL_nativeInitGL(JNIEnv* env,
        jobject defaultObj, jint w, jint h) {
    
    device = createDevice( video::EDT_OGLES1, dimension2d<u32>(w, h), 16, false, false, false, 0);
 
I think the current android port work only with native activity. creation of device is depend on struct android_app* app, which in my case 0.
I think we need to have another creation of device which support initialising irrlich on already existing GL Surface.
I will try to find a solution but if any one has tips :-) i will be happy.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Native Android port

Post by Nadro »

Yes, Irrlicht under Android require Native Activity.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Native Android port

Post by mazataza »

Ok.
I will try to modify CIrrDeviceAndroid to add support without a native activity and create an example to draw irrlicht in at least 2 Surfaces to check if it work well.
If i success i will post the patch here. so you can review it.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Native Android port

Post by Nadro »

Thanks a lot! :)
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Native Android port

Post by mazataza »

I have made some changes to CIrrDeviceAndroid to not use the activity.

here is my native code which create the device and initilaize

Code: Select all

 
#include <jni.h>
 
#include <irrlicht.h>
#include <android/native_window_jni.h>
#include <android_native_app_glue.h>
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
IrrlichtDevice *device = NULL;
IVideoDriver* driver = NULL;
 
ISceneManager* smgr;
IGUIEnvironment* guienv;
ANativeWindow* window;
int width = 0;
int height = 0;
static android_app android;
 
/* For JNI: C++ compiler need this */
extern "C" {
 
jint Java_com_amazweb_irrilichexample_NativeGL_nativeInitGL(JNIEnv* env,
        jobject defaultObj, jobject surface, jint w, jint h) {
 
    window = ANativeWindow_fromSurface(env, surface);
    if (window) {
        width = w;
        height = h;
        android.window = window;
        SIrrlichtCreationParameters p;
        p.DriverType = video::EDT_OGLES1;
        p.WindowSize = dimension2d<u32> (w, h);
        p.Bits = (u8) 16;
        p.Fullscreen = false;
        p.Stencilbuffer = false;
        p.Vsync = false;
        p.EventReceiver = 0;
        p.PrivateData = (void *) &android;
        device = createDeviceEx(p);
        if (device) {
            driver = device->getVideoDriver();
            if (driver) {
                ISceneManager* smgr = device->getSceneManager();
                IGUIEnvironment* guienv = device->getGUIEnvironment();
                IGUIStaticText* text = guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
                        rect<s32>(10,10,260,22), true);
                return 1;
            }
        }
    }
 
    return 0;
}
 
void Java_com_amazweb_irrilichexample_NativeGL_nativeDrawFrame(JNIEnv* env) {
 
    /*
     Anything can be drawn between a beginScene() and an endScene()
     call. The beginScene() call clears the screen with a color and
     the depth buffer, if desired. Then we let the Scene Manager and
     the GUI Environment draw their content. With the endScene()
     call everything is presented on the screen.
     */
    driver->beginScene(true, true, SColor(255, 100, 101, 140));
 
    //smgr->drawAll();
    //guienv->drawAll();
 
    driver->endScene();
}
 
}
 

Code: Select all

 
public class NativeGL implements Callback, Runnable {
 
    private static final String IRR_LICHT_NATIVE_GL_THREAD = "IrrLicht Native GL Thread";
 
    private SurfaceView surfaceView;
 
    private boolean destroy = false;
 
    public NativeGL(SurfaceView surfaceView) {
        this.surfaceView = surfaceView;
    }
 
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        int ok = nativeInitGL(holder.getSurface(), surfaceView.getWidth(),
                surfaceView.getHeight());
        Log.d("IrrLicht NativeGL", "" + ok);
        if (ok == 1) {
            Thread thread = new Thread(this, IRR_LICHT_NATIVE_GL_THREAD);
            thread.start();
        }
 
    }
 
    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        synchronized (surfaceView) {
            destroy = true;
        }
    }
 
    native int nativeInitGL(Surface surface, int w, int h);
 
    native void nativeDrawFrame();
 
    @Override
    public void run() {
        while (true) {
            synchronized (surfaceView) {
                if (destroy) {
                    break;
                }
            }
            try {
                nativeDrawFrame();
                Thread.sleep(1);
            } catch (InterruptedException e) {
                Log.d(IRR_LICHT_NATIVE_GL_THREAD,
                        "Sleep interrupted: " + e.getMessage());
            }
 
        }
    }
}
 
but i got only a black screen allthow i set on beginScene a background color. maybe i missed something.
I run the code inside an emulator.
here is the output

Code: Select all

 
01-22 22:07:57.265: D/dalvikvm(565): Trying to load lib /data/data/com.amazweb.irrilichexample/lib/libirrilichexample.so 0x40636060
01-22 22:07:57.605: D/dalvikvm(565): Added shared lib /data/data/com.amazweb.irrilichexample/lib/libirrilichexample.so 0x40636060
01-22 22:07:57.605: D/dalvikvm(565): No JNI_OnLoad found in /data/data/com.amazweb.irrilichexample/lib/libirrilichexample.so 0x40636060, skipping init
01-22 22:07:58.225: V/TLINE(565): new: android.text.TextLine@40659728
01-22 22:07:58.635: E/Irrlicht(565): Irrlicht Engine version 1.8.0-alpha
01-22 22:07:58.685: D/libEGL(565): egl.cfg not found, using default config
01-22 22:07:58.715: D/libEGL(565): loaded /system/lib/egl/libGLES_android.so
01-22 22:07:58.735: E/Irrlicht(565): EGL version: 1.400000
01-22 22:07:58.745: E/Irrlicht(565): Using renderer: OpenGL ES-CM 1.0
01-22 22:07:58.745: E/Irrlicht(565): OpenGL ES
01-22 22:07:58.745: E/Irrlicht(565): Android
01-22 22:07:58.755: E/Irrlicht(565): EGL_KHR_image EGL_KHR_image_base EGL_KHR_image_pixmap EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_KHR_fence_sync EGL_ANDROID_image_native_buffer EGL_ANDROID_swap_rectangle 
01-22 22:07:58.755: E/Irrlicht(565): GL_OES_byte_coordinates GL_OES_fixed_point GL_OES_single_precision GL_OES_read_format GL_OES_compressed_paletted_texture GL_OES_draw_texture GL_OES_matrix_get GL_OES_query_matrix GL_OES_EGL_image GL_OES_compressed_ETC1_RGB8_texture GL_ARB_texture_compression GL_ARB_texture_non_power_of_two GL_ANDROID_user_clip_plane GL_ANDROID_vertex_buffer_object GL_ANDROID_generate_mipmap 
01-22 22:07:58.755: E/libEGL(565): called unimplemented OpenGL ES API
01-22 22:07:58.755: E/libEGL(565): called unimplemented OpenGL ES API
01-22 22:07:58.755: E/libEGL(565): called unimplemented OpenGL ES API
01-22 22:07:58.755: E/libEGL(565): called unimplemented OpenGL ES API
01-22 22:07:58.765: E/libEGL(565): called unimplemented OpenGL ES API
01-22 22:07:58.865: D/IrrLicht NativeGL(565): 1
 
does someone has any hints why the black screen?
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Native Android port

Post by mazataza »

I got something work :D

I could draw a Box and display a text. I have tested only on Emulator (I got here 7 FPS, it is too poor)

I commend those line in CIrrDeviceAndroid.cpp, because it crash here for some reason.

Code: Select all

 
//io::CAndroidAssetFileArchive *assets = io::createAndroidAssetFileArchive(false, false);
    //assets->addDirectory("media");
    //FileSystem->addFileArchive(assets);
 
I didn't find why although i give the assest manager from java like

Code: Select all

 
        AAssetManager* mgr = AAssetManager_fromJava(jenv, assetManager);
 
Andi.Dascalu
Posts: 14
Joined: Wed Sep 21, 2011 6:44 am

Re: Native Android port

Post by Andi.Dascalu »

Hello,

Could someone direct me to the download link, or svn or git repository for this ?
I've browsed the thread a few times and couldn't find anything.

Thanks.
Andi.Dascalu
Posts: 14
Joined: Wed Sep 21, 2011 6:44 am

Re: Native Android port

Post by Andi.Dascalu »

Never mind.
Found it: https://irrlicht.svn.sourceforge.net/sv ... es/ogl-es/.

Thanks for the work!
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Native Android port

Post by mazataza »

I could say i could use Java Activity with A surface view on which irrlicht draw. As soon as i clean up the code i will post the patch here.

I have a small problem on Android emulator. when loading the Quake3 map in my Samsung Galaxy S1 it work very fine and i got 54 FPS, but when running it on Emulator no textures could be loaded. I got the following error!

Code: Select all

 
GL_INVALID_ENUM
Could not glTextImage2D
 
Did someone has any Idea about this error!
mchiasson
Posts: 12
Joined: Wed Feb 01, 2012 12:29 pm
Location: Ottawa, Ontario, Canada

Re: Native Android port

Post by mchiasson »

I am pretty certain that the Android emulator cannot do OpenGL ES, unless it was changed recently.
mchiasson
Posts: 12
Joined: Wed Feb 01, 2012 12:29 pm
Location: Ottawa, Ontario, Canada

Re: Native Android port

Post by mchiasson »

and the latest as of today doesn't seem to compile for Android.

First, I went in source/Irrlicht/Android/jni/Android.mk, and changed this line:

LOCAL_CFLAGS := -DBUILD_OGLES2 -g -D_DEBUG

to the following:

LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_ -g -D_DEBUG

But I am getting the following error:

jni/../../Irrlicht.cpp: In function 'irr::IrrlichtDevice* irr::createDeviceEx(const irr::SIrrlichtCreationParameters&)':
jni/../../Irrlicht.cpp:115:38: error: cannot allocate an object of abstract type 'irr::CIrrDeviceAndroid'
jni/../../CIrrDeviceAndroid.h:22:8: note: because the following virtual functions are pure within 'irr::CIrrDeviceAndroid':
../../../include/IrrlichtDevice.h:240:29: note: virtual irr::core::position2di irr::IrrlichtDevice::getWindowPosition()
Post Reply