Android Port

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Android Port

Post by hendu »

Depending on your target hw, you may want to use other terrain options such as: http://irrlicht.sourceforge.net/forum/v ... hp?t=48680
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Android Port

Post by mikkis »

Today I spend hours to make android example to work in my phone. I didnt see anything on the screen (only clearing color works).

Finally I got it to work. I changed

Code: Select all

 
param.WindowSize = dimension2d<u32>(0,0); // using 0,0 it will automatically set it to the maximal size
 
to

Code: Select all

 
param.WindowSize = dimension2d<u32>(200,300);
 
so maybe that (0,0) doesnt work with API10 (android 2.3.x)?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android Port

Post by CuteAlien »

Hm, I'm using API10, so that's not the problem.
It usually happens after the APP_CMD_INIT_WINDOW even which is handled in CIrrDeviceAndroid::handleAndroidCommand in CIrrDeviceAndroid.cpp

The code it calls there is the same we use now in the example:

Code: Select all

 
ANativeWindow* nativeWindow = static_cast<ANativeWindow*>(driver->getExposedVideoData().OGLESAndroid.Window);
    int32_t windowWidth = ANativeWindow_getWidth(app->window);
    int32_t windowHeight = ANativeWindow_getHeight(app->window);
 
We print the result of that as Window size later on in the example so it would be interesting to know what those values are in your device.

Only other reason I coudl think of is that APP_CMD_INIT_WINDOW maybe never get's called in your case for some reason? Wouldn't know why that could happen right now - but you could check if the console contains the message "Android command APP_CMD_INIT_WINDOW" that would help.
You can see that with logcat as described in the example.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Android Port

Post by mikkis »

Logcat seems to show sizes right.
E:\CPP\irrlicht-ogl-es\examples\27.HelloWorld_Android\bin>call adb logcat Irrlicht:V *:S
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/Irrlicht( 1287): Irrlicht Engine version 1.9.0
I/Irrlicht( 1287): Waiting for Android activity window to be created.
I/Irrlicht( 1287): Android command APP_CMD_RESUME
I/Irrlicht( 1287): Android command APP_CMD_INIT_WINDOW
I/Irrlicht( 1287): EGL version: 1.400000
I/Irrlicht( 1287): Using renderer: OpenGL ES 2.0 1566933
I/Irrlicht( 1287): Qualcomm
I/Irrlicht( 1287): GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_A
MD_program_binary_Z400 GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_B
GRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_NV_fence GL_OES_compressed_ETC1_RG
B8_texture GL_OES_depth_texture GL_OES_depth24 GL_OES_EGL_image GL_OES_EGL_image
_external GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_fragment_pre
cision_high GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_rgb8_rg
ba8 GL_OES_standard_derivatives GL_OES_texture_3D GL_OES_texture_float GL_OES_te
xture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_ver
tex_half_float GL_OES_vertex_type_10_10_10_2 GL_QCOM_binning_control GL_QCOM_dri
ver_control GL_QCOM_perfmon_global_mode GL_QCOM_extended_get GL_QCOM_extended_ge
t2 GL_QCOM_tiled_rendering GL_QCOM_writeonly_rendering GL_QCOM_memory_monitor GL
_AMD_compressed_3DC_texture
I/Irrlicht( 1287): Android command APP_CMD_GAINED_FOCUS
I/Irrlicht( 1287): Window size:(240/320)
I/Irrlicht( 1287): Display size:(240/320)
I/Irrlicht( 1287): PNG warning: iCCP: known incorrect sRGB profile
I/Irrlicht( 1287): PNG warning: iCCP: known incorrect sRGB profile
I/Irrlicht( 1287): Loaded texture: media/irrlichtlogo3.png
I/Irrlicht( 1287): Loaded mesh: media/sydney.md2
I/Irrlicht( 1287): Loaded texture: media/img.png
I/Irrlicht( 1287): Android command APP_CMD_PAUSE
I/Irrlicht( 1287): Android command APP_CMD_LOST_FOCUS
I/Irrlicht( 1287): Android command APP_CMD_TERM_WINDOW
I/Irrlicht( 1287): Android command APP_CMD_STOP
I/Irrlicht( 1287): Android command APP_CMD_DESTROY
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android Port

Post by CuteAlien »

And APP_CMD_INIT_WINDOW is also run... can't really say I got an idea right now.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Android Port

Post by mikkis »

Some debugging. I print width and height in void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd) method in CIrrDeviceAndroid.cpp:

Code: Select all

 
            if (device->CreationParams.WindowSize.Width == 0 || device->CreationParams.WindowSize.Height == 0)
            {
                device->CreationParams.WindowSize.Width = ANativeWindow_getWidth(app->window);
                device->CreationParams.WindowSize.Height = ANativeWindow_getHeight(app->window);
 
char txt[1000];
sprintf(txt, "##> %d %d\n",device->CreationParams.WindowSize.Width , device->CreationParams.WindowSize.Height );
os::Printer::log(txt, ELL_DEBUG);
            }
 
It shows
I/Irrlicht( 2033): Android command APP_CMD_INIT_WINDOW
I/Irrlicht( 2033): ##> 1 1
I/Irrlicht( 2033):
I/Irrlicht( 2033): EGL version: 1.400000
I/Irrlicht( 2033): Using renderer: OpenGL ES 2.0 1566933
I/Irrlicht( 2033): Qualcomm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android Port

Post by CuteAlien »

-1 would make more sense - that would be the error code. But maybe a device can create a window with 1,1 and resize them later to the real size? You could try if a patch like the following would work:

Code: Select all

 
Index: CIrrDeviceAndroid.cpp
===================================================================
--- CIrrDeviceAndroid.cpp       (revision 4694)
+++ CIrrDeviceAndroid.cpp       (working copy)
@@ -211,6 +211,8 @@
                        {
                                device->CreationParams.WindowSize.Width = ANativeWindow_getWidth(app->window);
                                device->CreationParams.WindowSize.Height = ANativeWindow_getHeight(app->window);
+                               if ( device->CreationParams.WindowSize.Width == 1 && device->CreationParams.WindowSize.Height == 1 )
+                                       break;
                        }
 
                        device->getContextManager()->initialize(device->CreationParams, device->ExposedVideoData);
@@ -232,6 +234,29 @@
                        }
                        device->Initialized = true;
                break;
+               case APP_CMD_WINDOW_RESIZED:
+                       if (!device->Initialized)
+                       {
+                               device->CreationParams.WindowSize.Width = ANativeWindow_getWidth(app->window);
+                               device->CreationParams.WindowSize.Height = ANativeWindow_getHeight(app->window);
+                               device->getContextManager()->initialize(device->CreationParams, device->ExposedVideoData);
+                               device->getContextManager()->generateSurface();
+                               device->getContextManager()->generateContext();
+                               device->getContextManager()->activateContext(device->getContextManager()->getContext());
+
+                               io::CAndroidAssetFileArchive* assets = new io::CAndroidAssetFileArchive( device->Android->activity->assetManager, false, false);
+                               assets->addDirectoryToFileList("");
+                               device->FileSystem->addFileArchive(assets);
+                               assets->drop();
+
+                               device->createDriver();
+                                                                                                                                 
+                               if (device->VideoDriver)                                                                          
+                                       device->createGUIAndScene();                                                              
+                                                                                                                                 
+                               device->Initialized = true;                                                                       
+                       }                                                                                                         
+               break;                                                                                                            
                case APP_CMD_TERM_WINDOW:                                                                                         
                        os::Printer::log("Android command APP_CMD_TERM_WINDOW", ELL_DEBUG);                                       
                        device->getContextManager()->destroySurface();                                
 
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
BinMa
Posts: 19
Joined: Wed Feb 19, 2014 8:59 am

Re: Android Port

Post by BinMa »

Hi, I'm now porting a game using this ogl-es version on Android. It works nice till now(at least I can see the main menu LOL). I have a question about the IME part. Will IME support be a part of later plan?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android Port

Post by CuteAlien »

I suppose I will need that input stuff it in some way as well in my project. But haven't worked on it yet.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
BinMa
Posts: 19
Joined: Wed Feb 19, 2014 8:59 am

Re: Android Port

Post by BinMa »

I'm now trying to transfer the touch event to fake gui events. Realizing there so much work to do to do the transfer one by one. Is there any easier way?
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Android Port

Post by mikkis »

CuteAlien wrote: You could try if a patch like the following would work:
Tried but there comes no resize.
I/Irrlicht( 2370): Irrlicht Engine version 1.9.0
I/Irrlicht( 2370): Waiting for Android activity window to be created.
I/Irrlicht( 2370): Android command APP_CMD_RESUME
I/Irrlicht( 2370): Android command APP_CMD_INIT_WINDOW
I/Irrlicht( 2370): Android command APP_CMD_GAINED_FOCUS
It just stops (with black screen).
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android Port

Post by CuteAlien »

@BinMa: I've not done that yet, but my plan was try IGUIEnvironment::postEventFromUser and send mouse-click-events for the touch-events.

@mikkis: Thanks for trying. If I understand that right you get the correct values for ANativeWindow_getWidth/ANativeWindow_getHeight later on even in the black screen case? It just doesn't work in APP_CMD_INIT_WINDOW? I googled around a little and right now there's 3 more ideas which could affect this. First would be that the window-size is set in APP_CMD_CONFIG_CHANGED. Second would be that window might need to be locked before callling ANativeWindow_getWidth. And third would be - that it maybe still takes some time for some reason - so instead of checking the size in APP_CMD_INIT_WINDOW we would have to start some timer and check after xxx time has passed again.

Sorry - I'm not really an expert yet with all that and unfortunately got no HTC One to test myself.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Android Port

Post by mikkis »

If I understand that right you get the correct values for ANativeWindow_getWidth/ANativeWindow_getHeight later on even in the black screen case?
Well they were still 1,1 because it didnt go to RESIZE and setted them.

But I got this to work, dont know is this right way but it works on my phone.
So, if I get 1,1, then I create surface, get width and height, then destroy it, and create it again using right width and height.
Index: CIrrDeviceAndroid.cpp
===================================================================
--- CIrrDeviceAndroid.cpp (revision 4695)
+++ CIrrDeviceAndroid.cpp (working copy)
@@ -211,6 +211,16 @@
{
device->CreationParams.WindowSize.Width = ANativeWindow_getWidth(app->window);
device->CreationParams.WindowSize.Height = ANativeWindow_getHeight(app->window);
+ if ( device->CreationParams.WindowSize.Width == 1 && device->CreationParams.WindowSize.Height == 1 )
+ {
+ device->getContextManager()->initialize(device->CreationParams, device->ExposedVideoData);
+ device->getContextManager()->generateSurface();
+ device->getContextManager()->generateContext();
+ device->getContextManager()->activateContext(device->getContextManager()->getContext());
+ device->CreationParams.WindowSize.Width = ANativeWindow_getWidth(app->window);
+ device->CreationParams.WindowSize.Height = ANativeWindow_getHeight(app->window);
+ device->getContextManager()->destroySurface();
+ }
}

device->getContextManager()->initialize(device->CreationParams, device->ExposedVideoData);
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android Port

Post by CuteAlien »

Hm, I'm not familiar enough yet with the context manager to know what's going on there. Maybe Nadro has an idea why that would work. One guess would be - this stuff takes some time - so doing a sleep( ... some amount of time... ) or just a big loop might also work.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Android Port

Post by mikkis »

I tried sleep earlier

Code: Select all

 
{
if (device->CreationParams.WindowSize.Width == 0 || device->CreationParams.WindowSize.Height == 0)
{
   device->sleep(1000, false); // sleeps one second
   device->CreationParams.WindowSize.Width = ANativeWindow_getWidth(app->window);
   device->CreationParams.WindowSize.Height = ANativeWindow_getHeight(app->window);
 
 
width and height was still 1,1.
Post Reply