Android and Ogre Wiki Tutorial Framework

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
celticsoul
Gnoblar
Posts: 2
Joined: Mon Feb 18, 2013 5:29 am

Android and Ogre Wiki Tutorial Framework

Post by celticsoul »

I have successfully compiled Ogre for android in my ArchLinux and SampleBroswer works fine on my phone. I've been struggling to get the Ogre Wiki Tutorial Framework (MinimalOgre) to work on Android and the SampleBrowser code is too complicated and mixed with code for other platforms.
Any tutorial to show how to display a simple ogrehead.mesh on Android would be great help.
Thanks.
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 135
Contact:

Re: Android and Ogre Wiki Tutorial Framework

Post by spacegaier »

Murat started some days ago on two Ogre Android samples that should soon be found in the official Ogre repository for you to have a look at. But they will still use the SampleBrowser as the foundation.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: Android and Ogre Wiki Tutorial Framework

Post by Wolfmanfx »

Nope the two samples do not use any code from the samplebrowser :) so the are really self contained and simple and just showing one mesh.
celticsoul
Gnoblar
Posts: 2
Joined: Mon Feb 18, 2013 5:29 am

Re: Android and Ogre Wiki Tutorial Framework

Post by celticsoul »

While waiting for the new samples in the repo, can someone help me with this problem:
My app crashes whenever I call root->initialise

Code: Select all

void android_main(struct android_app* state)
{
	// Create application object
	MainApplication app;
	app_dummy();

	try {
		app.go(state);
	} catch (Ogre::Exception& e) {
		std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl;
	}
}
My MainApplication.cpp

Code: Select all

bool MainApplication::go(struct android_app* state)
{
/*
#ifdef _DEBUG
    mResourcesCfg = "resources_d.cfg";
    mPluginsCfg = "plugins_d.cfg";
#else
    mResourcesCfg = "resources.cfg";
    mPluginsCfg = "plugins.cfg";
#endif

    // construct Ogre::Root
    mRoot = new Ogre::Root(mPluginsCfg);
*/

	mAssetMgr = state->activity->assetManager;
	Ogre::FileSystemLayer* mFSLayer;

	mFSLayer = OGRE_NEW_T(Ogre::FileSystemLayer, Ogre::MEMCATEGORY_GENERAL)(OGRE_VERSION_NAME);

	mRoot = new Ogre::Root();

    g_gles2Plugin = OGRE_NEW Ogre::GLES2Plugin();
    Ogre::Root::getSingleton().installPlugin(g_gles2Plugin);

    // Grab the available render systems
    const Ogre::RenderSystemList &renderSystemList = mRoot->getAvailableRenderers();
    if(renderSystemList.empty())
    {
    	LOGI("+++ renderSystemList.empty()");
       return false;
    }

    // Set the render system and init
    Ogre::RenderSystem *system = renderSystemList.front();
    mRoot->setRenderSystem(system);
    mRoot->getRenderSystem()->_initRenderTargets();

    Ogre::ArchiveManager::getSingleton().addArchiveFactory(new Ogre::APKFileSystemArchiveFactory(mAssetMgr));
    Ogre::ArchiveManager::getSingleton().addArchiveFactory(new Ogre::APKZipArchiveFactory(mAssetMgr));

        //mRoot->setRenderSystem(mRoot->getAvailableRenderers().at(0));
    //mRoot->initialise(false);


//-------------------------------------------------------------------------------------
    // setup resources
    // Load resource paths from config file
    Ogre::ConfigFile cf;
    cf.load(openAPKFile(mFSLayer->getConfigFilePath("resources.cfg")));

    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }

    LOGI("+++ mRoot->initialise(...) launching..........................................................................");
    mWindow = mRoot->initialise(true, "MainApplication Render Window");
    LOGI("+++ mRoot->initialise(...) is done");
/*
//-------------------------------------------------------------------------------------
    // configure
    // Show the configuration dialog and initialise the system
    // You can skip this and use root.restoreConfig() to load configuration
    // settings if you were sure there are valid ones saved in ogre.cfg
    if(mRoot->restoreConfig() || mRoot->showConfigDialog())
    {
        // If returned true, user clicked OK so initialise
        // Here we choose to let the system create a default rendering window by passing 'true'
        mWindow = mRoot->initialise(true, "MainApplication Render Window");
    }
    else
    {
        LOGI("+++ Fail to configure....");
    }
*/
//-------------------------------------------------------------------------------------
    // choose scenemanager
    // Get the SceneManager, in this case a generic one
    mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
//-------------------------------------------------------------------------------------
    // create camera
    // Create the camera
    mCamera = mSceneMgr->createCamera("PlayerCam");

    // Position it at 500 in Z direction
    mCamera->setPosition(Ogre::Vector3(0,0,80));
    // Look back along -Z
    mCamera->lookAt(Ogre::Vector3(0,0,-300));
    mCamera->setNearClipDistance(5);

//-------------------------------------------------------------------------------------
    // create viewports
    // Create one viewport, entire window
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));

    // Alter the camera aspect ratio to match the viewport
    mCamera->setAspectRatio(
        Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
//-------------------------------------------------------------------------------------
    // Set default mipmap level (NB some APIs ignore this)
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
//-------------------------------------------------------------------------------------
    // Create any resource listeners (for loading screens)
    //createResourceListener();
//-------------------------------------------------------------------------------------
    // load resources
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
//-------------------------------------------------------------------------------------
    // Create the scene
    Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");

    Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    headNode->attachObject(ogreHead);

    // Set ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));

    // Create a light
    Ogre::Light* l = mSceneMgr->createLight("MainLight");
    l->setPosition(20,80,50);
//-------------------------------------------------------------------------------------

    while(true)
    {
        // Pump window messages for nice behaviour
        Ogre::WindowEventUtilities::messagePump();

        if(mWindow->isClosed())
        {
            return false;
        }

        // Render a frame
        if(!mRoot->renderOneFrame()) return false;
    }

    // We should never be able to reach this corner
    // but return true to calm down our compiler
    return true;
}
And the core dump

Code: Select all

I/OGRE    (25932): Creating resource group General
I/OGRE    (25932): Creating resource group Internal
I/OGRE    (25932): Creating resource group Autodetect
I/OGRE    (25932): SceneManagerFactory for type 'DefaultSceneManager' registered.
I/OGRE    (25932): Registering ResourceManager for type Material
I/OGRE    (25932): Registering ResourceManager for type Mesh
I/OGRE    (25932): Registering ResourceManager for type Skeleton
I/OGRE    (25932): MovableObjectFactory for type 'ParticleSystem' registered.
I/OGRE    (25932): ArchiveFactory for archive type FileSystem registered.
I/OGRE    (25932): ArchiveFactory for archive type Zip registered.
I/OGRE    (25932): ArchiveFactory for archive type EmbeddedZip registered.
I/OGRE    (25932): DDS codec registering
I/OGRE    (25932): FreeImage version: 3.15.3
I/OGRE    (25932): This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
I/OGRE    (25932): Supported formats: bmp,ico,jpg,jif,jpeg,jpe,jng,koa,iff,lbm,mng,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,gif,hdr,g3,sgi,exr,j2k,j2c,jp2,pfm,pct,pict,pic,3fr,arw,bay,bmq,cap,cine,cr2,crw,cs1,dc2,dcr,drf,dsc,dng,erf,fff,ia,iiq,k25,kc2,kdc,mdc,mef,mos,mrw,nef,nrw,orf,pef,ptx,pxn,qtk,raf,raw,rdc,rw2,rwl,rwz,sr2,srf,srw,sti
I/OGRE    (25932): PVRTC codec registering
I/OGRE    (25932): ETC1 codec registering
I/OGRE    (25932): Registering ResourceManager for type HighLevelGpuProgram
I/OGRE    (25932): Registering ResourceManager for type Compositor
I/OGRE    (25932): MovableObjectFactory for type 'Entity' registered.
I/OGRE    (25932): MovableObjectFactory for type 'Light' registered.
I/OGRE    (25932): MovableObjectFactory for type 'BillboardSet' registered.
I/OGRE    (25932): MovableObjectFactory for type 'ManualObject' registered.
I/OGRE    (25932): MovableObjectFactory for type 'BillboardChain' registered.
I/OGRE    (25932): MovableObjectFactory for type 'RibbonTrail' registered.
E/OGRE    (25932): OGRE EXCEPTION(6:FileNotFoundException): 'plugins.cfg' file not found! in ConfigFile::load at /mnt/data/projects/ogre/OgreMain/src/OgreConfigFile.cpp (line 88)
I/OGRE    (25932): plugins.cfg not found, automatic plugin loading disabled.
I/OGRE    (25932): *-*-* OGRE Initialising
I/OGRE    (25932): *-*-* Version 1.9.0unstable (Ghadamon)
I/OGRE    (25932): Installing plugin: OpenGL ES 2.0 RenderSystem
I/OGRE    (25932): OpenGL ES 2.x Rendering Subsystem created.
D/libEGL  (25932): loaded /system/lib/egl/libEGL_mali.so
D/libEGL  (25932): loaded /system/lib/egl/libGLESv1_CM_mali.so
D/libEGL  (25932): loaded /system/lib/egl/libGLESv2_mali.so
D/        (25932): Device driver API match
D/        (25932): Device driver API version: 10
D/        (25932): User space API version: 10 
D/        (25932): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Fri May  4 10:32:42 KST 2012 
I/OGRE    (25932): Plugin successfully installed
I/OGRE    (25932): ArchiveFactory for archive type APKFileSystem registered.
I/OGRE    (25932): ArchiveFactory for archive type APKZip registered.
I/OGRE    (25932): Creating resource group Essential
D/OpenGLRenderer( 2252): Flushing caches (mode 0)
I/OGRE    (25932): Added resource location '/thumbnails' of type 'APKFileSystem' to resource group 'Essential'
I/OGRE    (25932): Added resource location '/packs/SdkTrays.zip' of type 'APKZip' to resource group 'Essential'
D/dalvikvm(25897): GC_CONCURRENT freed 1021K, 9% free 12271K/13383K, paused 2ms+3ms
I/AudioPolicyManager( 1624): stopOutput() output 1, stream 1, session 118
I/AudioFlinger( 1624): stop output streamType (0, 1) for 1
E/DataRouter( 1619): DrReadUsbStatus returns false USB is offline 
E/DataRouter( 1619): DrReadUsbStatus returns false USB is offline 
D/dalvikvm( 1839): GC_CONCURRENT freed 5190K, 28% free 22891K/31687K, paused 4ms+12ms
I/OGRE    (25932): Added resource location '/' of type 'APKFileSystem' to resource group 'General'
I/OGRE    (25932): Creating resource group Popular
I/OGRE    (25932): Added resource location '/fonts' of type 'APKFileSystem' to resource group 'Popular'
D/dalvikvm(25897): GC_FOR_ALLOC freed 711K, 8% free 12335K/13383K, paused 40ms
I/dalvikvm-heap(25897): Grow heap (frag case) to 12.257MB for 131088-byte allocation
I/SurfaceFlinger( 1621): id=117 Removed Launcher idx=3 Map Size=4
I/SurfaceFlinger( 1621): id=117 Removed Launcher idx=-2 Map Size=4
D/dalvikvm(25897): GC_FOR_ALLOC freed 2K, 9% free 12461K/13575K, paused 38ms
I/OGRE    (25932): Added resource location '/materials/programs' of type 'APKFileSystem' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/materials/programs/GLSLES' of type 'APKFileSystem' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/materials/scripts' of type 'APKFileSystem' to resource group 'Popular'
W/WifiStateTracker( 1839): getNetworkInfo : NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
V/yamaha::media::VolumeCtrl( 1624): VolumeCtrl::createVolume()
D/yamaha::media::VolumeCtrl( 1624): Dir0      : AP Playback Music SP (0001h)
D/yamaha::media::VolumeCtrl( 1624): Dir0Att   : AP Playback Music SP (0001h)
D/yamaha::media::VolumeCtrl( 1624): DacMaster : AP Playback Music SP (0001h)
D/yamaha::media::VolumeCtrl( 1624): Sp        : AP Playback Music SP (FD81h)
V/yamaha::media::UserDep( 1624): UserDep::getRouteInfo(output: audioengine=0, devices=00000002h
V/yamaha::media::UserDep( 1624):                       incall: onoff=0, devices=00000000h
V/yamaha::media::UserDep( 1624):                       capture: onoff=0, devices=00000000h, audioSource=0
V/yamaha::media::UserDep( 1624):                       playback: audio_onoff=1, line_onoff=0)
V/yamaha::media::UserDep( 1624): Playback[Audio], Output[dev:DAC, NonAE]
V/yamaha::media::UserDep( 1624): editDacDst(devices=2h) HPOUT Off
V/yamaha::media::UserDep( 1624): editDacDst(devices=2h) RCOUT Off
V/yamaha::media::UserDep( 1624): editDacDst(devices=2h) LINEOUT1 Off
V/yamaha::media::VolumeCtrl( 1624): VolumeCtrl::setVolume()
D/yamaha::media::VolumeCtrl( 1624): VolumeCtrl::setVolume() FM Playback: Ready
D/yamaha::media::VolumeCtrl( 1624): VolumeCtrl::setVolume() VoiceCall: Ready
I/OGRE    (25932): Added resource location '/materials/textures' of type 'APKFileSystem' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/materials/textures/nvidia' of type 'APKFileSystem' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/models' of type 'APKFileSystem' to resource group 'Popular'
D/dalvikvm( 1839): GC_EXPLICIT freed 6188K, 47% free 16814K/31687K, paused 3ms+6ms
E/AlarmManagerService( 1839): android_server_AlarmManagerService_set to type=3, 24270.929000000
D/dalvikvm(25897): GC_CONCURRENT freed 791K, 7% free 12823K/13703K, paused 4ms+5ms
I/OGRE    (25932): Added resource location '/particle' of type 'APKFileSystem' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/RTShaderLib' of type 'APKFileSystem' to resource group 'Popular'
D/comsamsungapp(25616): [MSC]>>> SCI:3883 [0:0] [AS]N1361177273245
D/comsamsungapp(25616): [MSC]>>> WIM:28 [0:0] 401 0
D/comsamsungapp(25616): [MSC]>>> WIM:28 [0:0] 201 1
D/comsamsungapp(25616): [MSC]>>> WIM:34 [0:0] get() : Ids1 = 8
D/comsamsungapp(25616): [MSC]>>> SCI:3961 [0:0] find 005930KS
D/comsamsungapp(25616): [MSC]>>> SCI:3970 [0:0] fi ne inx=1
D/KeyguardViewMediator( 1839): handleTimeout
I/OGRE    (25932): Added resource location '/RTShaderLib/GLSLES' of type 'APKFileSystem' to resource group 'Popular'
D/comsamsungapp(25616): [MSC]>>> SCI:5229 [0:0] set in 1893018093%
E/lights  ( 1839): write_int: path /sys/devices/virtual/sec/sec_touchkey/brightness, value 2
W/PowerManagerService( 1839): Timer 0x7->0x3|0x0
I/PowerManagerService( 1839): Ulight 7->3|0
D/PowerManagerService( 1839): setLightBrightness : mButtonLight : 0
I/OGRE    (25932): Added resource location '/RTShaderLib/materials' of type 'APKFileSystem' to resource group 'Popular'
D/dalvikvm(25616): GC_CONCURRENT freed 428K, 6% free 9361K/9927K, paused 2ms+6ms
I/OGRE    (25932): Added resource location '/materials/scripts/SSAO' of type 'APKFileSystem' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/materials/textures/SSAO' of type 'APKFileSystem' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/packs/cubemap.zip' of type 'APKZip' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/packs/cubemapsJS.zip' of type 'APKZip' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/packs/dragon.zip' of type 'APKZip' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/packs/fresneldemo.zip' of type 'APKZip' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/packs/ogretestmap.zip' of type 'APKZip' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/packs/ogredance.zip' of type 'APKZip' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/packs/Sinbad.zip' of type 'APKZip' to resource group 'Popular'
I/OGRE    (25932): Added resource location '/packs/skybox.zip' of type 'APKZip' to resource group 'Popular'
I/Ogre    (25932): +++ mRoot->initialise(...) launching..........................................................................
I/OGRE    (25932): CPU Identifier & Features
I/OGRE    (25932): -------------------------
I/OGRE    (25932):  *   CPU ID: ARMv7
I/OGRE    (25932):  *      VFP: yes
I/OGRE    (25932):  *     NEON: yes
I/OGRE    (25932): -------------------------
I/OGRE    (25932): Registering ResourceManager for type Texture
I/OGRE    (25932): GLES2RenderSystem::_createRenderWindow "MainApplication Render Window", 1280x800 fullscreen  miscParams: FSAA= displayFrequency=0 MHz 
F/libc    (25932): Fatal signal 11 (SIGSEGV) at 0x00000058 (code=1)
D/dalvikvm(25897): GC_CONCURRENT freed 991K, 8% free 13070K/14151K, paused 4ms+4ms
W/CursorWrapperInner(25897): Cursor finalized without prior close()
W/WifiStateTracker( 1839): getNetworkInfo : NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
W/WifiStateTracker( 1839): getNetworkInfo : NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
W/WifiStateTracker( 1839): getNetworkInfo : NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
W/WifiStateTracker( 1839): getNetworkInfo : NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
I/power   ( 1839): *** release_dvfs_lock : lockType : 1 
D/PowerManagerService( 1839): releaseDVFSLockLocked : all DVFS_MIN_LIMIT are released 
W/ActivityManager( 1839): mDVFSLock.release()
E/AlarmManagerService( 1839): android_server_AlarmManagerService_set to type=3, 24279.950000000
I/DEBUG   ( 1617): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   ( 1617): Build fingerprint: 'samsung/GT-I9100/GT-I9100:4.0.4/IMM76D/XWLPT:user/release-keys'
I/DEBUG   ( 1617): pid: 25932, tid: 25948  >>> net.phamngochai.heroesofwar <<<
I/DEBUG   ( 1617): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000058
I/DEBUG   ( 1617):  r0 00000000  r1 00000005  r2 00000000  r3 00000004
I/DEBUG   ( 1617):  r4 513b39b8  r5 00000000  r6 00000000  r7 5124eaf4
I/DEBUG   ( 1617):  r8 00003020  r9 00003040  10 00000004  fp 00000000
I/DEBUG   ( 1617):  ip 5124ed70  sp 513a79c8  lr 50d8c148  pc 4dd53baa  cpsr 20000030
I/DEBUG   ( 1617):  d0  65757165003f4800  d1  5f3a3a6d65747373
I/DEBUG   ( 1617):  d2  6552657461657270  d3  646e69577265646c
I/DEBUG   ( 1617):  d4  2e2e2e2e2e2e2e2e  d5  2e2e2e2e2e2e2e2e
I/DEBUG   ( 1617):  d6  4026000000000000  d7  003f480000000000
I/DEBUG   ( 1617):  d8  0000000000000000  d9  0000000000000000
I/DEBUG   ( 1617):  d10 0000000000000000  d11 0000000000000000
I/DEBUG   ( 1617):  d12 0000000000000000  d13 0000000000000000
I/DEBUG   ( 1617):  d14 0000000000000000  d15 0000000000000000
I/DEBUG   ( 1617):  d16 414fa40040000000  d17 3fe0000000000000
I/DEBUG   ( 1617):  d18 41c44bc5ac800000  d19 0000000000000000
I/DEBUG   ( 1617):  d20 0000000000000000  d21 0000000000000000
I/DEBUG   ( 1617):  d22 3ff0000000000000  d23 0000000000000000
I/DEBUG   ( 1617):  d24 3ff0000000000000  d25 0000000000000000
I/DEBUG   ( 1617):  d26 0000000000000000  d27 0000000000000000
I/DEBUG   ( 1617):  d28 ffffffffffffffff  d29 ffffffffffffffff
I/DEBUG   ( 1617):  d30 0000000000000000  d31 0000000000000000
I/DEBUG   ( 1617):  scr 80000012
I/DEBUG   ( 1617): 
I/DEBUG   ( 1617):          #00  pc 00009baa  /system/lib/libandroid.so (ANativeWindow_setBuffersGeometry)
I/DEBUG   ( 1617):          #01  lr 50d8c148  /data/data/net.phamngochai.heroesofwar/lib/libhow-activity.so
I/DEBUG   ( 1617): 
I/DEBUG   ( 1617): code around pc:
I/DEBUG   ( 1617): 4dd53b88 2101b510 ffeef7ff bf00bd10 2102b510  ...!...........!
I/DEBUG   ( 1617): 4dd53b98 ffe8f7ff bf00bd10 460eb5f7 93004615  ...........F.F..
I/DEBUG   ( 1617): 4dd53ba8 6d872105 462b4632 47b84604 3e00b958  .!.m2F+F.F.GX..>
I/DEBUG   ( 1617): 4dd53bb8 2601bf18 2d006da3 2200bf0c 0201f006  ...&.m.-..."....
I/DEBUG   ( 1617): 4dd53bc8 210a4620 bdfe4798 460db570 6d844613   F.!.G..p..F.F.m
I/DEBUG   ( 1617): 
I/DEBUG   ( 1617): code around lr:
I/DEBUG   ( 1617): 50d8c128 e58400b0 e59400ac ebfe7388 e1a01006  .........s......
I/DEBUG   ( 1617): 50d8c138 e1a02006 e59d3014 e59400a4 ebfe7386  . ...0.......s..
I/DEBUG   ( 1617): 50d8c148 e1a00004 e59410ac e59420a4 eb0018f9  ......... ......
I/DEBUG   ( 1617): 50d8c158 e1550006 e58400b4 0a000020 e1a00005  ..U..... .......
I/DEBUG   ( 1617): 50d8c168 ebfe7380 e594509c e59f1144 e28d2008  .s...P..D.... ..
I/DEBUG   ( 1617): 
I/DEBUG   ( 1617): stack:
I/DEBUG   ( 1617):     513a7988  00000001  
I/DEBUG   ( 1617):     513a798c  60000006  
I/DEBUG   ( 1617):     513a7990  00000001  
I/DEBUG   ( 1617):     513a7994  513a79fc  
I/DEBUG   ( 1617):     513a7998  0000302e  
I/DEBUG   ( 1617):     513a799c  00003040  
I/DEBUG   ( 1617):     513a79a0  00000004  
I/DEBUG   ( 1617):     513a79a4  521b4b74  /system/lib/egl/libEGL_mali.so
I/DEBUG   ( 1617):     513a79a8  00edd398  [heap]
I/DEBUG   ( 1617):     513a79ac  00000005  
I/DEBUG   ( 1617):     513a79b0  0000302e  
I/DEBUG   ( 1617):     513a79b4  521b4b1c  /system/lib/egl/libEGL_mali.so
I/DEBUG   ( 1617):     513a79b8  513a79fc  
I/DEBUG   ( 1617):     513a79bc  00000001  
I/DEBUG   ( 1617):     513a79c0  df0027ad  
I/DEBUG   ( 1617):     513a79c4  00000000  
I/DEBUG   ( 1617): #00 513a79c8  00000004  
I/DEBUG   ( 1617):     513a79cc  00000000  
I/DEBUG   ( 1617):     513a79d0  00000000  
I/DEBUG   ( 1617):     513a79d4  513b39b8  
I/DEBUG   ( 1617):     513a79d8  00000000  
I/DEBUG   ( 1617):     513a79dc  00000000  
I/DEBUG   ( 1617):     513a79e0  5124eaf4  /data/data/net.phamngochai.heroesofwar/lib/libhow-activity.so
I/DEBUG   ( 1617):     513a79e4  50d8c148  /data/data/net.phamngochai.heroesofwar/lib/libhow-activity.so
I/DEBUG   ( 1617):     513a79e8  00f1a469  [heap]
I/DEBUG   ( 1617):     513a79ec  4012c099  /system/lib/libc.so
I/DEBUG   ( 1617):     513a79f0  00000003  
I/DEBUG   ( 1617):     513a79f4  50d51920  /data/data/net.phamngochai.heroesofwar/lib/libhow-activity.so
I/DEBUG   ( 1617):     513a79f8  513a7b80  
I/DEBUG   ( 1617):     513a79fc  00000004  
I/DEBUG   ( 1617):     513a7a00  513a7a31  
I/DEBUG   ( 1617):     513a7a04  00000021  
I/DEBUG   ( 1617):     513a7a08  00003040  
I/DEBUG   ( 1617):     513a7a0c  00000004  
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 135
Contact:

Re: Android and Ogre Wiki Tutorial Framework

Post by spacegaier »

Wolfmanfx wrote:Nope the two samples do not use any code from the samplebrowser :) so the are really self contained and simple and just showing one mesh.
Ah, then I misunderstood you earlier. Even better for the thread opener ;) .
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: Android and Ogre Wiki Tutorial Framework

Post by Wolfmanfx »

The code you post can not work at this point you do not have a valid surface to render and there is more wrong the best thing would to wait until the SDK is released (its already done) so you can use it as a base app.
Emerich
Halfling
Posts: 64
Joined: Wed Oct 24, 2012 10:59 am
x 12

Re: Android and Ogre Wiki Tutorial Framework

Post by Emerich »

Any news on the Ogre Samples? Would love to have some hints to work with =)
sfabien
Gnoblar
Posts: 8
Joined: Wed Nov 18, 2009 4:46 pm

Re: Android and Ogre Wiki Tutorial Framework

Post by sfabien »

Emerich wrote:Any news on the Ogre Samples? Would love to have some hints to work with =)
Same question here, have to start a new project on Android. Any idea on the "release date" so that i can plan my work ?

Thanks !
Djoulihen
Gnoblar
Posts: 5
Joined: Wed Mar 27, 2013 4:28 pm

Re: Android and Ogre Wiki Tutorial Framework

Post by Djoulihen »

I have also been trying to create a minimal ogre application (no input, just showing a mesh on the screen) running on android. I painfully went through the code of the SampleBrowser and extracted what I thought to be the minimal code needed. By combining it with the android native application example I have ended with the following (in one big file) :

Code: Select all

#include <jni.h>
#include <errno.h>

#include <android/log.h>
#include <android_native_app_glue.h>

#include <EGL/egl.h>

#include "OgreRoot.h"
#include "OgrePlatform.h"
#include "OgreFileSystemLayer.h"

#include "Android/OgreAPKFileSystemArchive.h"
#include "Android/OgreAPKZipArchive.h"
#include "Android/OgreAndroidEGLWindow.h"


#ifdef OGRE_STATIC_LIB

#define OGRE_STATIC_GLES2
#define OGRE_STATIC_OctreeSceneManager

#include "OgreStaticPluginLoader.h"

#endif

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "app", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "app", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "app", __VA_ARGS__))

/**
 * Our saved state data.
 */
struct saved_state
{
};

/**
 * Shared state for our app.
 */
struct app_user_data
{
  android_app *android_app_state;

  bool init;
  bool animating;

  Ogre::RenderWindow *window;
  Ogre::Root *root;

  saved_state state;

#ifdef OGRE_STATIC_LIB
  Ogre::StaticPluginLoader *plugin_loader;
#endif
};




static Ogre::DataStreamPtr openAPKFile(AAssetManager* asset_manager, const Ogre::String& fileName)
{
  Ogre::DataStreamPtr stream;
  AAsset* asset = AAssetManager_open(asset_manager, fileName.c_str(), AASSET_MODE_BUFFER);
  if (asset)
  {
    off_t length = AAsset_getLength(asset);
    void* membuf = OGRE_MALLOC(length, Ogre::MEMCATEGORY_GENERAL);
    memcpy(membuf, AAsset_getBuffer(asset), length);
    AAsset_close(asset);

    stream = Ogre::DataStreamPtr(new Ogre::MemoryDataStream(membuf, length, true, true));
  }
  return stream;
}


static void ogre_app_init(app_user_data *data)
{
  LOGI("Init ogre app");

  /********************************* Misc ****************************/

  Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);

  // Ogre::Root::getSingleton().getRenderSystem()->_initRenderTargets();

  // // Clear event times
  // Ogre::Root::getSingleton().clearEventTimes();


  /********************************* Load resources ****************************/

  Ogre::ArchiveManager::getSingleton().addArchiveFactory(
    new Ogre::APKFileSystemArchiveFactory(data->android_app_state->activity->assetManager)
    );

  Ogre::ArchiveManager::getSingleton().addArchiveFactory(
    new Ogre::APKZipArchiveFactory(data->android_app_state->activity->assetManager)
    );

  Ogre::FileSystemLayer fs_layer(OGRE_VERSION_NAME);
  Ogre::ConfigFile cf;
  cf.load(openAPKFile(data->android_app_state->activity->assetManager,
                      fs_layer.getConfigFilePath("resources.cfg")));

  Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
  Ogre::String sec, type, arch;

  // go through all specified resource groups
  while (seci.hasMoreElements())
  {
    sec = seci.peekNextKey();
    Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext();
    Ogre::ConfigFile::SettingsMultiMap::iterator i;

    // go through all resource paths
    for (i = settings->begin(); i != settings->end(); i++)
    {
      type = i->first;
      arch = i->second;

      Ogre::ResourceGroupManager::getSingleton().addResourceLocation(arch, type, sec);
    }
  }

  Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();


  /********************************* Create Scene ****************************/

  // Create the SceneManager, in this case a generic one
  Ogre::SceneManager *scene_manager = Ogre::Root::getSingleton().createSceneManager("DefaultSceneManager");

  // Create the camera
  Ogre::Camera *camera = scene_manager->createCamera("PlayerCam");

  // Look back along -Z
  camera->setPosition(Ogre::Vector3(0,0,100));
  camera->lookAt(Ogre::Vector3(0,0,-300));
  camera->setNearClipDistance(5);
  camera->setFarClipDistance(5000);

  // Create one viewport, entire window
  Ogre::Viewport* vp = data->window->addViewport(camera);
  vp->setBackgroundColour(Ogre::ColourValue(0.5,0,0));

  // Alter the camera aspect ratio to match the viewport
  camera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

  Ogre::Entity* ogreHead = scene_manager->createEntity("Head", "ogrehead.mesh");

  Ogre::SceneNode* headNode = scene_manager->getRootSceneNode()->createChildSceneNode();
  headNode->attachObject(ogreHead);

  Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);

  Ogre::MeshManager::getSingleton().createPlane("ground",
                                                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                plane, 1500, 1500, 20, 20, true,
                                                1, 5, 5, Ogre::Vector3::UNIT_Z);

  Ogre::Entity* entGround = scene_manager->createEntity("GroundEntity", "ground");
  scene_manager->getRootSceneNode()->createChildSceneNode()->attachObject(entGround);

  entGround->setMaterialName("Examples/Rocky");
  entGround->setCastShadows(false);

  // Set ambient light
  scene_manager->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));

  // Create a light
  Ogre::Light* l = scene_manager->createLight("MainLight");
  l->setPosition(20,80,50);
}


static int app_setup_display(app_user_data* data)
{
  LOGI("Setup display");

  AConfiguration *config = AConfiguration_new();
  AConfiguration_fromAssetManager(config, data->android_app_state->activity->assetManager);

  if (data->window == nullptr)
  {
    Ogre::NameValuePairList opt;
    opt["externalWindowHandle"] = Ogre::StringConverter::toString((int)data->android_app_state->window);
    opt["androidConfig"] = Ogre::StringConverter::toString((int)config);

    data->window = Ogre::Root::getSingleton().createRenderWindow("OgreWindow", 0, 0, false, &opt);
    ogre_app_init(data);
  }
  else
  {
    static_cast<Ogre::AndroidEGLWindow*>(data->window)->_createInternalResources(
      data->android_app_state->window, config
      );
  }

  AConfiguration_delete(config);

  return 0;
}

static void app_term_display(app_user_data* data)
{
  LOGI("Terminate display");
  static_cast<Ogre::AndroidEGLWindow*>(data->window)->_destroyInternalResources();
}

static void app_draw_frame(app_user_data* data)
{
  if(data->window != nullptr && data->window->isActive())
  {
    // LOGI("Render frame");
    // data->window->windowMovedOrResized();
    data->root->renderOneFrame();
  }
}


static void app_init(app_user_data* data)
{
  LOGI("App init");
  if(data->init == true)
    return;

  data->root = new Ogre::Root();

#ifdef OGRE_STATIC_LIB
  data->plugin_loader = new Ogre::StaticPluginLoader();
  data->plugin_loader->load();
#endif

  data->root->setRenderSystem(data->root->getAvailableRenderers().at(0));
  data->root->initialise(false);
  data->init = true;
}

static void app_shutdown(app_user_data* data)
{
  LOGI("App shutdown");
  app_term_display(data);

  if (data->init == false)
  {
    return;
  }

  data->init = false;

  delete data->root;
  data->root = nullptr;
  data->window = nullptr;

#ifdef OGRE_STATIC_LIB
  data->plugin_loader->unload();
  delete data->plugin_loader;
  data->plugin_loader = nullptr;
#endif
}

/**
 * Process the next input event.
 */
static int32_t app_handle_input(android_app */*app*/, AInputEvent *event)
{
  LOGI("Input received");
  if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
  {
    return 1;
  }
  return 0;
}

/**
 * Process the next main command.
 */
static void app_handle_cmd(android_app *app, int32_t cmd)
{
  app_user_data* data = (app_user_data *) app->userData;
  switch (cmd)
  {
  case APP_CMD_SAVE_STATE:
    LOGI("Save state command");
    // The system has asked us to save our current state.  Do so.
    app->savedState = malloc(sizeof(saved_state));
    *((saved_state*)app->savedState) = data->state;
    app->savedStateSize = sizeof(saved_state);
    break;

  case APP_CMD_INIT_WINDOW:
    LOGI("Init window command");
    // The window is being shown, get it ready.
    if (app->window != nullptr && data->init == true)
    {
      app_setup_display(data);
      app_draw_frame(data);
    }
    break;

  case APP_CMD_TERM_WINDOW:
    LOGI("Term window command");
    if(data->init == true && data->window != nullptr)
    {
      // The window is being hidden or closed, clean it up.
      app_term_display(data);
    }
    break;

  case APP_CMD_GAINED_FOCUS:
    data->animating = true;
    break;

  case APP_CMD_LOST_FOCUS:
    data->animating = false;
    break;

  default:
    LOGI("Other command");
    break;
  }
}

/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void android_main(android_app* state)
{
  LOGI("Starting app");
  app_user_data data;

  // Make sure glue isn't stripped.
  app_dummy();

  memset(&data, 0, sizeof(data));
  data.android_app_state = state;
  data.init = false;
  data.animating = false;
  app_init(&data);

  state->userData = &data;
  state->onAppCmd = app_handle_cmd;
  state->onInputEvent = app_handle_input;

  if (state->savedState != NULL)
  {
    // We are starting with a previous saved state; restore from it.
    data.state = *(saved_state*)state->savedState;
  }

  // loop waiting for stuff to do.
  while (1)
  {
    // Read all pending events.
    int ident;
    int events;
    android_poll_source* source;

    // LOGI("Polling events");
    // If not animating, we will block forever waiting for events.
    // If animating, we loop until all events are read, then continue
    // to draw the next frame of animation.
    while ((ident = ALooper_pollAll(data.animating ? 0 : -1, NULL, &events, (void**)&source)) >= 0)
    {
      // Process this event.
      if (source != NULL)
      {
        source->process(state, source);
      }

      // Check if we are exiting.
      if (state->destroyRequested != 0)
      {
        app_shutdown(&data);
        return;
      }
    }

    // LOGI("Drawing frame");
    if (data.animating == true)
    {
      app_draw_frame(&data);
    }
  }
}
What is strange is that the application runs correctly and even displays a red screen (I changed the background color of the viewport to see if ogre was doing anything). But I cannot see any of the meshes created in the scene. The log does not report any error apart from the usual plugins.cfg being not found. I feel like I am just missing something simple. I managed to get something displayed once but could never reproduce.

Any help would be greatly appreciated, otherwise I guess I will be waiting for the official minimal application to be released.
Attachments
log.txt
(19.45 KiB) Downloaded 164 times
arf_rinux
Gnoblar
Posts: 5
Joined: Sat Sep 21, 2013 2:45 pm

Re: Android and Ogre Wiki Tutorial Framework

Post by arf_rinux »

I have exactly the same problem.
here my code

Code: Select all

#include <jni.h>
#include <EGL/egl.h>
#include <android/api-level.h>
#include "arf_log.h"
#include "android_native_app_glue.h"
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#include "OgrePlatform.h"
#include "OgreRoot.h"
#include "OgreRenderWindow.h"
#include "OgreArchiveManager.h"
#include "OgreFileSystemLayer.h"
#include "OgreEntity.h"
#include "Android/OgreAndroidEGLWindow.h"
#include "Android/OgreAPKFileSystemArchive.h"
#include "Android/OgreAPKZipArchive.h"

#ifdef OGRE_BUILD_PLUGIN_OCTREE
#	include "OgreOctreePlugin.h"
#endif

#ifdef OGRE_BUILD_PLUGIN_PFX
#	include "OgreParticleFXPlugin.h"
#endif

#ifdef OGRE_BUILD_COMPONENT_OVERLAY
#	include "OgreOverlaySystem.h"
#endif

#include "OgreConfigFile.h"

#ifdef OGRE_BUILD_RENDERSYSTEM_GLES2
#	include "OgreGLES2Plugin.h"
#	define GLESRS GLES2Plugin
#else
#	include "OgreGLESPlugin.h"
#	define GLESRS GLESPlugin
#endif


using namespace Ogre;

#ifdef OGRE_BUILD_PLUGIN_OCTREE
static Ogre::OctreePlugin* mOctreePlugin = NULL;
#endif

#ifdef OGRE_BUILD_PLUGIN_PFX
static Ogre::ParticleFXPlugin* mParticleFXPlugin = NULL;
#endif

#ifdef OGRE_BUILD_COMPONENT_OVERLAY
static Ogre::OverlaySystem* mOverlaySystem = NULL;
#endif

static Ogre::GLESRS* mGLESPlugin = NULL;
static Ogre::SceneManager* mSceneMgr = NULL;
static Ogre::Camera* mCamera = NULL;
static Ogre::RenderWindow* mRenderWnd;
static Ogre::Root* mRoot;
static Rectangle2D* mRect = NULL;
static Ogre::FileSystemLayer* mFSLayer = NULL; // File system abstraction layer
static AAssetManager* mAssetMgr = NULL;
static bool mInit = false;

static void OgreNative_handle_cmd(struct android_app* app, int32_t cmd);
static void shutdown();
static int32_t OgreNative_handleInput(struct android_app* app, AInputEvent* event);
static void init(struct android_app* state);
static void go(struct android_app* state);
static void locateResources(void);
static void loadResources(void);
static Ogre::DataStreamPtr openAPKFile(const Ogre::String& fileName);

void loadResources(void)
{
	// Set default mipmap level (note: some APIs ignore this)
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}

Ogre::DataStreamPtr openAPKFile(const Ogre::String& fileName)
{
    Ogre::DataStreamPtr stream;
    if (!mAssetMgr)
    {
    	LOGE("AssetManager not initialized.");
    	stream.setNull();
    	return stream;
    }
    AAsset* asset = AAssetManager_open(mAssetMgr, fileName.c_str(), AASSET_MODE_BUFFER);
    if(asset)
    {
        off_t length = AAsset_getLength(asset);
        void* membuf = OGRE_MALLOC(length, Ogre::MEMCATEGORY_GENERAL);
        memcpy(membuf, AAsset_getBuffer(asset), length);
        AAsset_close(asset);

        stream = Ogre::DataStreamPtr(new Ogre::MemoryDataStream(membuf, length, true, true));
    }
    return stream;
}

void locateResources(void)
{
	// load resource paths from config file
	Ogre::ConfigFile cf;

	cf.load(openAPKFile(mFSLayer->getConfigFilePath("resources.cfg")));
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
	Ogre::String sec, type, arch;

	// go through all specified resource groups
	while (seci.hasMoreElements())
	{
		sec = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;

		// go through all resource paths
		for (i = settings->begin(); i != settings->end(); i++)
		{
			type = i->first;
			arch = i->second;
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(arch, type, sec);
		}

	}
}

static void shutdown()
{
	LOGI("The Ogre Native Test Application Shutting down");

	if(!mInit)
		return;

	mInit = false;

#ifdef OGRE_BUILD_COMPONENT_OVERLAY
	LOGI("Destroy OverlaySysem");
	if(mOverlaySystem) OGRE_DELETE mOverlaySystem;
	mOverlaySystem = NULL;
#endif

	LOGI("Destroy Rect (used for the background)");
	if(mRect) OGRE_DELETE mRect;
	mRect = NULL;

	LOGI("Destroy OgreRoot");
	if(mRoot) OGRE_DELETE mRoot;
	mRoot = NULL;
	mRenderWnd = NULL;
	mCamera = NULL;
	mSceneMgr = NULL;

#ifdef OGRE_BUILD_PLUGIN_PFX
	LOGI("Destroy ParticleFXPlugin");
	if(mParticleFXPlugin) OGRE_DELETE mParticleFXPlugin;
	mParticleFXPlugin = NULL;
#endif

#ifdef OGRE_BUILD_PLUGIN_OCTREE
	LOGI("Destroy OctreePlugin");
	if(mOctreePlugin) OGRE_DELETE mOctreePlugin;
	mOctreePlugin = NULL;
#endif

	LOGI("Destroy GLESPlugin");
	if(mGLESPlugin) OGRE_DELETE mGLESPlugin;
	mGLESPlugin = NULL;

	LOGI("Destroy FileSystemLayer");
	if(mFSLayer) OGRE_DELETE_T(mFSLayer, FileSystemLayer, Ogre::MEMCATEGORY_GENERAL);
	mFSLayer = NULL;
}

static int32_t OgreNative_handleInput(struct android_app* app, AInputEvent* event)
{
	int wPosX, wPosY, wActKey, wKeyCod;

    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
    {
    	wPosX = AMotionEvent_getX(event, 0);
    	wPosY = AMotionEvent_getY(event, 0);
    	LOG_D("TouchScreen Event: X:%d - Y:%d", wPosX, wPosY);
        return 1;
    }
    else if(AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY)
    {
    	wActKey = AKeyEvent_getAction(event);
    	wKeyCod = AKeyEvent_getKeyCode(event);
    	if (wKeyCod == AKEYCODE_BACK || wKeyCod == AKEYCODE_HOME)
    	{
    		/**
    		 * TODO:
    		 * Close the app maybe... but I still don't know how
    		 */
    	}
    	LOG_D("Key Event: Action:%d - Code:%d", wActKey, wKeyCod);
    	return 1;
    }

    return 0;
}

/**
 * Process the next main command.
 */
static void OgreNative_handle_cmd(struct android_app* app, int32_t cmd) {
	switch (cmd) {
	case APP_CMD_SAVE_STATE:
		LOGI("APP_CMD_SAVE_STATE: implement something if needed.");
		/**
		 * TODO: implement something if needed
		 *
		 */
		break;
	case APP_CMD_INIT_WINDOW:
		// The window is being shown, get it ready.
		LOGI("APP_CMD_INIT_WINDOW: The window is being shown, get it ready.");
		if (app->window && mRoot)
		{
			AConfiguration* config = AConfiguration_new();
			AConfiguration_fromAssetManager(config, app->activity->assetManager);

			if (!mRenderWnd)
			{
				Ogre::NameValuePairList opt;
				opt["externalWindowHandle"] = Ogre::StringConverter::toString((int)app->window);
				opt["androidConfig"] = Ogre::StringConverter::toString((int)config);

				mRenderWnd = Ogre::Root::getSingleton().createRenderWindow("OgreWindow", 0, 0, false, &opt);

				if(mSceneMgr == NULL)
				{
					mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);

					mCamera = mSceneMgr->createCamera("MyCam");
					// Position it at 80 in Z direction
					mCamera->setPosition(Ogre::Vector3(0,0,80));
					// Look back along -Z
					mCamera->lookAt(Ogre::Vector3(0,0,-300));
					mCamera->setNearClipDistance(5);

					// Create one viewport, entire window
					Ogre::Viewport* vp = mRenderWnd->addViewport(mCamera);
					vp->setBackgroundColour(Ogre::ColourValue(1,0,0));

					// Alter the camera aspect ratio to match the viewport
					mCamera->setAspectRatio(
					Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

					/***
					 * Here I'm testing how to create a beckground coverd with a texture
					 */
					// Create background material
					MaterialPtr mBackgroundMaterial = MaterialManager::getSingleton().create("Background", "General");
					mBackgroundMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("rockwall.tga");
					mBackgroundMaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
					mBackgroundMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
					mBackgroundMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);

					// Create background rectangle covering the whole screen
					mRect = new Rectangle2D(true);
					mRect->setCorners(-1.0, 1.0, 1.0, -1.0);
					mRect->setMaterial("Background");

					// Render the background before everything else
					mRect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);

					// Use infinite AAB to always stay visible
					AxisAlignedBox aabInf;
					aabInf.setInfinite();
					mRect->setBoundingBox(aabInf);

					// Attach background to the scene
					SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background");
					node->attachObject(mRect);

					Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");

					Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
					headNode->attachObject(ogreHead);

					// Set ambient light
					mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));

					// Create a light
					Ogre::Light* l = mSceneMgr->createLight("MainLight");
					l->setPosition(20,80,50);

					// Example of background scrolling
					//mBackgroundMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setScrollAnimation(-0.25, 0.0);

				}
			}
			else
			{
				static_cast<AndroidEGLWindow*>(mRenderWnd)->_createInternalResources(app->window, NULL);
			}

			AConfiguration_delete(config);
		}

		break;
	case APP_CMD_TERM_WINDOW:
		// The window is being hidden or closed, clean it up.
		LOGI("APP_CMD_TERM_WINDOW: The window is being hidden or closed, clean it up.");
		if(mRoot && mRenderWnd)
		{
			static_cast<AndroidEGLWindow*>(mRenderWnd)->_destroyInternalResources();
			shutdown();
		}
		break;
	case APP_CMD_GAINED_FOCUS:
		// When our app gains focus.
		LOGI("APP_CMD_GAINED_FOCUS: When our app gains focus.");
		break;
	case APP_CMD_LOST_FOCUS:
		break;
	case APP_CMD_DESTROY:
		break;
	}
}

static void init(struct android_app* app)
{
	LOGI("The Ogre Native Test Application INIT");

	app->onAppCmd = &OgreNative_handle_cmd;
	app->onInputEvent = &OgreNative_handleInput;

	if(mInit)
		return;

	mRoot = new Ogre::Root();
	mGLESPlugin = OGRE_NEW GLESRS();
	mRoot->installPlugin(mGLESPlugin);

#ifdef OGRE_BUILD_PLUGIN_OCTREE
	mOctreePlugin = OGRE_NEW OctreePlugin();
	mRoot->installPlugin(mOctreePlugin);
#endif

#ifdef OGRE_BUILD_PLUGIN_PFX
	mParticleFXPlugin = OGRE_NEW ParticleFXPlugin();
	mRoot->installPlugin(mParticleFXPlugin);
#endif

#ifdef OGRE_BUILD_COMPONENT_OVERLAY
	mOverlaySystem = OGRE_NEW OverlaySystem();
#endif

    mRoot->setRenderSystem(mRoot->getAvailableRenderers().at(0));
	mRoot->initialise(false);
	mInit = true;

	mAssetMgr = app->activity->assetManager;
	if (mAssetMgr)
	{
		ArchiveManager::getSingleton().addArchiveFactory( new APKFileSystemArchiveFactory(mAssetMgr) );
		ArchiveManager::getSingleton().addArchiveFactory( new APKZipArchiveFactory(mAssetMgr) );
	}
	mFSLayer = OGRE_NEW_T(Ogre::FileSystemLayer, Ogre::MEMCATEGORY_GENERAL)(OGRE_VERSION_NAME);

	locateResources();
	loadResources();

	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);

	Ogre::Root::getSingleton().getRenderSystem()->_initRenderTargets();

	// Clear event times
	Ogre::Root::getSingleton().clearEventTimes();

	LOGI("The Ogre Native Test Application INIT DONE");
}

static void go(struct android_app* state)
{
	int ident, events;
	struct android_poll_source* source;

	LOGI("The Ogre Native Test Application GO");

	while (true)
	{
		while ((ident = ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0)
		{
			if (source != NULL)
				source->process(state, source);

			if (state->destroyRequested != 0)
				return;
		}

		if(mRenderWnd != NULL && mRenderWnd->isActive())
		{
			mRenderWnd->windowMovedOrResized();
			if(!mRoot->renderOneFrame())
			{
				LOGI("IN MAIN LOOP: renderOneFrame returned false.");
				break;
			}
			LOG_D("---> ONE FRAME IS RENDERED<---");
		}
	}
}

/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void android_main(struct android_app* state) {

	// Make sure glue isn't stripped.
	app_dummy();

	init(state);
	go(state);

}
Below there is the log.
Also for my any error and I see a red background but no 2D background with a texture and no ogrehead.mesh diplayed.

What am I doing wrong?
Attachments
log.txt
This is the log of my Android simple test application.
(18.61 KiB) Downloaded 136 times
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Android and Ogre Wiki Tutorial Framework

Post by c6burns »

You aren't going to see anything just by dropping an entity in the scene, as GLES2 has no FFP. So you either enable RTSS or use a material with your own shaders. There's a thread where robert was kind enough to show a code example for initializing RTSS, so you don't have to dig through the samplebrowser ... let me see ...

Here: http://www.ogre3d.org/forums/viewtopic.php?f=21&t=78160
arf_rinux
Gnoblar
Posts: 5
Joined: Sat Sep 21, 2013 2:45 pm

Re: Android and Ogre Wiki Tutorial Framework

Post by arf_rinux »

Many thanks! That worked! I've got my test apllication running and rendering properly.
I'll go to document myself on the topic in orther to understand better the use of the RTSS.
If you have some reccomendation I'll appiciate it!
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Android and Ogre Wiki Tutorial Framework

Post by c6burns »

I didn't understand at first that RTSS is used for FFP emulation ... basically what it means is that if you just want to use material files and not create shaders by hand, you can do that in your GLES2 app. That's definitely the easiest way to get up and running in a project, and a testament to the awesomeness of RTSS. In terms of creating custom shaders with RTSS I know very little, as I've been using GLSL for shaders and not using RTSS in my current project.
josemi
Gnoblar
Posts: 20
Joined: Tue Jun 25, 2013 8:54 am
Location: Spain

Re: Android and Ogre Wiki Tutorial Framework

Post by josemi »

sfabien wrote:
Emerich wrote:Any news on the Ogre Samples? Would love to have some hints to work with =)
Same question here, have to start a new project on Android. Any idea on the "release date" so that i can plan my work ?

Thanks !

Have been published the source or the samples?? it would be very very helpful since I'm trying to show a mesh in android and it is not working :(
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Android and Ogre Wiki Tutorial Framework

Post by c6burns »

You can easily get it working yourself ... the example is 99% and the other 1% is right here in this thread and the thread that was linked. Just take the time to read and understand.
josemi
Gnoblar
Posts: 20
Joined: Tue Jun 25, 2013 8:54 am
Location: Spain

Re: Android and Ogre Wiki Tutorial Framework

Post by josemi »

Ok, I have a ogre floating head , and even it reacts on touching the screen! :D
Buuuut... The head is white, it has no texture, how can I load it? Did I miss something?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Android and Ogre Wiki Tutorial Framework

Post by c6burns »

I put an example in this thread since for some reason it looked more related to JNI development: http://www.ogre3d.org/forums/viewtopic.php?f=21&t=78160

You probably didn't load the material that the mesh is using. Use adb logcat to check your app's output for exceptions, etc
Post Reply