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 »

No, Irrlicht require native activity.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
sohamdutta13
Posts: 3
Joined: Wed Feb 19, 2014 4:59 am

Re: Native Android port

Post by sohamdutta13 »

I am using a surfaceview in java for camera with the QCAR library. this is in ogles 2 and i need to pass the context of that view to the irrlicht natice activity. the problem i am facing is that i have the view for QCAR in java and the irrlicht in the native code. is there anyway to make them use the same surface?
Right now running them parallely makes the irrlicht surface overlap the QCAR camera view.
Agent_X
Posts: 41
Joined: Sun Sep 16, 2012 3:44 am

Re: Native Android port

Post by Agent_X »

I've come to consult the oracle! I'm trying to get the back button on the device to emulate a keyboard escape key press. By default the back button causes the NativeActivity to run finish() which effectively closes the app. I can get it to ignore presses of the back button, but I want it to post an escape key event to Irrlicht. What I've done is added some code (shown below) to the handleInput() method in CIrrDeviceAndroid.cpp and then did a complete recompile of Irrlicht. What am I missing?

Code: Select all

 
if (AInputEvent_getType(androidEvent) == AINPUT_EVENT_TYPE_KEY)
{
    SEvent Event;
    Event.EventType = EET_KEY_INPUT_EVENT;
 
    if (AKeyEvent_getKeyCode(androidEvent) == AKEYCODE_BACK)
    {
        Event.KeyInput.Key = KEY_ESCAPE;
        Event.KeyInput.PressedDown = false;
        device->postEventFromUser(Event);
        Status = 1;
    }
}
 
This makes the Android device ignore presses of the back button while in the app, so I know I'm on the right track.
Agent_X
Posts: 41
Joined: Sun Sep 16, 2012 3:44 am

Re: Native Android port

Post by Agent_X »

I feel stupid now! :oops: There was a flaw in my program's event receiver code - I had it explicitly ignoring keyboard input if the platform was Android. Sorry for the mistake. By the way that bit of code works perfectly for controlling the behavior of the device's back button. The same concept could be used for the other Android action bar keys... :D
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Native Android port

Post by Nadro »

BTW. You don't have to recompile Irrlicht if you want change input controller etc. You can do something like that:
// H

Code: Select all

class GameAndroid
{
public:
    GameAndroid(android_app* pApplication);
 
    // some methods here
 
private:
    static void handleCommand(android_app* pApplication, int32_t pCommand);
    static int32_t handleInput(android_app* pApplication, AInputEvent* pEvent);
 
    static void (*irrlichtCommand)(android_app* pApplication, int32_t pCommand);
    static int32_t (*irrlichtInput)(android_app* pApplication, AInputEvent* pEvent);
};
// CPP

Code: Select all

void (*GameAndroid::irrlichtCommand)(android_app* pApplication, int32_t pCommand) = 0;
int32_t (*GameAndroid::irrlichtInput)(android_app* pApplication, AInputEvent* pEvent) = 0;
 
GameAndroid::GameAndroid(android_app* pApplication)
{
    // Init Irrlicht here -> createDevice
 
    irrlichtCommand = pApplication->onAppCmd;
    pApplication->onAppCmd = handleCommand;
 
    irrlichtInput = pApplication->onInputEvent;
    pApplication->onInputEvent = handleInput;
}
 
void GameAndroid::handleCommand(android_app* pApplication, int32_t pCommand)
{
    switch (pCommand)
    {
        case APP_CMD_GAINED_FOCUS:
            // Do something.
            irrlichtCommand(pApplication, pCommand);
            break;
        case APP_CMD_LOST_FOCUS:
            // Do something.
            irrlichtCommand(pApplication, pCommand);
        break;
        case APP_CMD_DESTROY:
            // Do something.
            break;
        default:
            irrlichtCommand(pApplication, pCommand);
            break;
    }
}
 
int32_t GameAndroid::handleInput(android_app* pApplication, AInputEvent* pEvent)
{
    int32_t Status = irrlichtInput(pApplication, pEvent);
 
    switch (AKeyEvent_getKeyCode(pEvent))
    {
    case AKEYCODE_BACK:
    case AKEYCODE_MENU:
        Status = 1;
        break;
    default:
        break;
    }
 
    return Status;
}
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Agent_X
Posts: 41
Joined: Sun Sep 16, 2012 3:44 am

Re: Native Android port

Post by Agent_X »

I initially tried to do it from inside my application code but I couldn't figure out how to tell the android_app object to execute the IrrlichtDevice's postEventFromUser() method. Now, looking at this example, I see what I was missing. Much cleaner. Thanks Nadro.
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Native Android port

Post by netpipe »

i found that with the latest ogl-es branch the resolution of (0,0) did not automatically set to the detected 320 x 480 on android 2.3 was seeing only a grey screen with one pixel out on the bottom left, after setting it manually it worked perfectly(except for some color glitching on sydney).

heres the original output using 0,0
I/Irrlicht(15825): Using renderer: OpenGL ES-CM 1.1
I/Irrlicht(15825): Qualcomm
I/Irrlicht(15825): GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_APPLE_texture_2D_limited_npot GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_OES_blend_equation_separate GL_OES_blend_func_separate GL_OES_blend_subtract GL_OES_compressed_ETC1_RGB8_texture GL_OES_compressed_paletted_texture GL_OES_depth_texture GL_OES_draw_texture GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_framebuffer_object GL_OES_matrix_palette GL_OES_packed_depth_stencil GL_OES_point_size_array GL_OES_point_sprite GL_OES_read_format GL_OES_rgb8_rgba8 GL_OES_stencil_wrap GL_OES_texture_cube_map GL_OES_texture_env_crossbar GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_texture_mirrored_repeat GL_QCOM_binning_control GL_QCOM_extended_get GL_QCOM_tiled_rendering GL_AMD_compressed_3DC_texture
I/Irrlicht(15825): GL_INVALID_ENUM
I/Irrlicht(15825): Could not bind Texture
I/Irrlicht(15825): Android command APP_CMD_GAINED_FOCUS
I/Irrlicht(15825): Window size:(320/480)
I/Irrlicht(15825): Display size:(320/480)
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Native Android port

Post by netpipe »

heres a cb project file that compiles and uploads via ndk via shell script
http://www.xup.to/dl,18903709/example_27_extras.7z/
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
bmiller
Posts: 4
Joined: Fri Jul 01, 2016 6:50 pm

Re: Native Android port

Post by bmiller »

sohamdutta13 wrote:Hi have you managed to run the irrrlicht engine without the native activity. i already have a glsurface that i am drawing on and i would like to draw the 3d model on that surface with irrlicht. the problem is that when i draw the 3d model the background becomes black. Also i am trying to accomplish this using gles 2
Did you find any way to use Irrlicht without a native activity (android_main) ?
Post Reply