Ogre 1.8 displays no Entity on Android

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
McTwist
Gnoblar
Posts: 2
Joined: Wed Jan 09, 2013 11:53 am

Ogre 1.8 displays no Entity on Android

Post by McTwist »

I have for quite some time now tried to port Ogre to Android. There was problem with cmake for cygwin to make the compilation, but after taking the code from Ogre 1.8 with pre-compiled dependencies, I managed to compile in Eclipse with some minor changes to solve compilation errors with parts from this mk file. Along with it was added initialization and drawing code specified here and parts from the sample code that came along Ogre. The startup code was made in Java with its dependencies, and later the native library was called in the same manner GameKit does, with two functions where one is the initialization and the other is the drawing routine. Due to Android limitations, NativeActivity is not used. Ogre and its dependencies are pre-compiled to reduce the time of the compilation when changes are made to the actual program.
Everything is loaded nicely, with proper debugging output and and no errors or crashes.

The problem that occurs is that even if everything works it doesn't display anything but the viewport background. The camera and the model loaded have been moved several times to ensure they are in the correct position. The viewport background color changes on the fly to verify the drawing routine is working properly. The compiled Ogre library was even copied to the Ogre sample program and compiled with success. Still, it does only display a black screen(Which probably could be changed to whatever color I like to).

Additional information on the setup:

Code: Select all

Eclipse: 4.2.1
Android SDK Tools: 21.0.1
Android NDK: r8c
Android API: 8
Ogre: 1.8
STL: gnustl(libc++)
ABI: armeabi-v7a
Features: exceptions rtti
OpenGL ES: 2.0
I have fallen flat to find a solution to this problem and it bugs me that GameKit managed to port their Ogre properly. Especially when I try to compile GameKit it gives the same problem as above, but when I use a pre-compiled version of GameKit, it works fine.

I assume that that I am clear at my point and the reader have the knowledge about said libraries. If there is any diffuse holes in my description I may explain it in further detail.
Artem
Gnoblar
Posts: 3
Joined: Thu Mar 14, 2013 8:28 am

Re: Ogre 1.8 displays no Entity on Android

Post by Artem »

I have the same problem!
I use Ogre v1.9 and project OgreJNI with SurfaceView. My view display only Viewport background and I don't see no Entities.

Code: Select all

/*
extern "C"
{
	JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
	{
        JNIEnv *env;
        jclass k;
        jint r;

		gVM = vm;
        r = vm->GetEnv ((void **) &env, JNI_VERSION_1_4);
        k = env->FindClass ("org/ogre3d/android/OgreActivityJNI");
	return JNI_VERSION_1_4;
	}

	JNIEXPORT void JNICALL 	Java_org_ogre3d_android_OgreActivityJNI_create(JNIEnv * env, jobject obj, jobject assetManager)
	{
        if(gInit)	return;
        gRoot = new Ogre::Root();

        gGLESPlugin = OGRE_NEW GLESRS();
		gRoot->installPlugin(gGLESPlugin);

		gOctreePlugin = OGRE_NEW OctreePlugin();
		gRoot->installPlugin(gOctreePlugin);

		gParticleFXPlugin = OGRE_NEW ParticleFXPlugin();
		gRoot->installPlugin(gParticleFXPlugin);

		 const Ogre::RenderSystemList &renderSystemList = gRoot->getAvailableRenderers();
		    if(renderSystemList.empty())
		    {
		    	__android_log_print(ANDROID_LOG_ERROR, OGRE_TAG,"+++ renderSystemList.empty()");

		    }

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

        mAssetMgr = AAssetManager_fromJava(env, assetManager);
		if (mAssetMgr == NULL) {
			__android_log_print(ANDROID_LOG_ERROR, OGRE_TAG,
					"Error loading asset   maanger");
		} else {
			__android_log_print(ANDROID_LOG_VERBOSE, OGRE_TAG,
					"Loaded Asset Manager!");
		}

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

        gInit = true;
	}

	JNIEXPORT void JNICALL Java_org_ogre3d_android_OgreActivityJNI_destroy(JNIEnv * env, jobject obj)
	{
		if(!gInit)
			return;

        gInit = false;

        OGRE_DELETE gRoot;
        gRoot = NULL;
        gRenderWnd = NULL;

		OGRE_DELETE gParticleFXPlugin;
		gParticleFXPlugin = NULL;

		OGRE_DELETE gOctreePlugin;
		gOctreePlugin = NULL;

		OGRE_DELETE gGLESPlugin;
		gGLESPlugin = NULL;

		OGRE_DELETE_T(mFSLayer, FileSystemLayer, Ogre::MEMCATEGORY_GENERAL);

	}


    JNIEXPORT void JNICALL Java_org_ogre3d_android_OgreActivityJNI_initWindow(JNIEnv * env, jobject obj,  jobject surface)
	{
		if(surface)
		{
			ANativeWindow* nativeWnd = ANativeWindow_fromSurface(env, surface);
			if (nativeWnd && gRoot)
			{

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

				Ogre::DataStreamPtr stream;
				AAsset* asset = AAssetManager_open(mAssetMgr, mFSLayer->getConfigFilePath("resources.cfg").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));
				            }

				Ogre::ConfigFile cf;
				cf.load(stream);

				// 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);
					}
				}

				if (!gRenderWnd)
				{
					Ogre::NameValuePairList opt;
					opt["externalWindowHandle"] = Ogre::StringConverter::toString((int)nativeWnd);
					gRenderWnd = Ogre::Root::getSingleton().createRenderWindow("OgreWindow", 200, 200, true, &opt);

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

						mCamera = mSceneMgr->createCamera("camera");
						mCamera->setPosition(Ogre::Vector3(50,50,50));
						mCamera->lookAt(Ogre::Vector3(5,5,5));
						
						  mViewport = gRenderWnd->addViewport(mCamera);
						  mViewport->setBackgroundColour(Ogre::ColourValue(0.25,0.5,0.5));						 
						  mCamera->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight()));

						  // light
						  mLight = mSceneMgr->createLight("Light");
						  mLight->setType(Ogre::Light::LT_POINT);
						  mLight->setSpecularColour(0.3,0.3,0.3);
						  mLight->setPosition(Ogre::Vector3(50, 50, 50));

						  mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
						  mSceneMgr->createLight()->setPosition(20, 80, 50);

						  // mesh

						  Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
						  mEntity = mSceneMgr->createEntity("Head", "Sinbad.mesh");

						  headNode->attachObject(mEntity);
						  headNode->setPosition(Ogre::Vector3(0,0,0));
                                        }				 

				}
				else
				{
					static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_createInternalResources(nativeWnd, NULL);
				}
			}
		}
	}

    JNIEXPORT void JNICALL Java_org_ogre3d_android_OgreActivityJNI_termWindow(JNIEnv * env, jobject obj)
	{
		if(gRoot && gRenderWnd)
		{
			static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_destroyInternalResources();
		}
	}

	JNIEXPORT void JNICALL Java_org_ogre3d_android_OgreActivityJNI_renderOneFrame(JNIEnv * env, jobject obj)
	{
		if(gRenderWnd != NULL && gRenderWnd->isActive())
		{
			try
			{
				if(gVM->AttachCurrentThread(&env, NULL) < 0)
					return;

				gRenderWnd->windowMovedOrResized();
				gRoot->renderOneFrame();

				//gVM->DetachCurrentThread();
			}catch(Ogre::RenderingAPIException ex) {}
		}
	}


};
In logger I have one error: Adreno200-ES20: <check_framebuffer_status:563>: GL_INVALID_OPERATION
Plz help me!!!!!! :D
Orobu
Gnoblar
Posts: 12
Joined: Tue Mar 26, 2013 7:39 pm
x 4

Re: Ogre 1.8 displays no Entity on Android

Post by Orobu »

I also like to add that I have the same problem as the two posters above me, using Ogre 1.9 with SurfaceView and OgreJNI. I can get the viewport to change color but that's it. My code looks pretty much the same as Artems and I get the same error in the log: "Adreno200-ES20: <check_framebuffer_status:563>: GL_INVALID_OPERATION". using a HTC Sensation XL. The sample browser built and works just fine when compiling Ogre for Android.
Zergeny
Gnoblar
Posts: 4
Joined: Fri Mar 29, 2013 2:23 pm

Re: Ogre 1.8 displays no Entity on Android

Post by Zergeny »

I have the same trouble( I'm using Ogre1.9 with precompiled AndroidDependencies_17_12_2012 and Nexus 7.. Interesting that the samples from the browser works fine, but if I try to do a scene in the project OgreJNI editing OgreActivityJNI.cpp, as does Artem... then displays only the specified viewport background color(
Zergeny
Gnoblar
Posts: 4
Joined: Fri Mar 29, 2013 2:23 pm

Re: Ogre 1.8 displays no Entity on Android

Post by Zergeny »

If you put this code into Java_org_ogre3d_android_OgreActivityJNI_initWindow after creating scene manager:

Code: Select all

#ifdef USE_RTSHADER_SYSTEM
Ogre::RTShader::ShaderGenerator::initialize();
gShaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
	// Create and register the material manager listener if it doesn't exist yet.
if (gMaterialMgrListener == NULL)
{
	gMaterialMgrListener = new ShaderGeneratorTechniqueResolverListener(mShaderGenerator);
	Ogre::MaterialManager::getSingleton().addListener(mMaterialMgrListener);
}
gShaderGenerator->addSceneManager(pSceneMgr);
#endif
you will see your scene in OgreJNI... That is why the the SampleBrowser shows entities, and the OgreJNI shows only background colour...
ShaderGeneratorTechniqueResolverListener declaration you can get from the SampleBrowser.h
and don't forgot add static members in OgreActivityJNI.cpp

Code: Select all

#ifdef USE_RTSHADER_SYSTEM
static Ogre::RTShader::ShaderGenerator*			gShaderGenerator;			// The Shader generator instance.
static OgreBites::ShaderGeneratorTechniqueResolverListener*	gMaterialMgrListener;		// Shader generator material manager listener.	
#endif // USE_RTSHADER_SYSTEM
Sorry for my English)
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: Ogre 1.8 displays no Entity on Android

Post by Wolfmanfx »

Checkout sf.net the precompiled sdk for android *hint* :)
Zergeny
Gnoblar
Posts: 4
Joined: Fri Mar 29, 2013 2:23 pm

Ogre 1.9 displays no Entity on Android

Post by Zergeny »

Precompiled OgreSDK_Android_v1-9-0RC1.7z 2013-04-14
Asus Nexus 7 (Android 4.2.2):
- Sample GLES2 works good but without RTShaderSystem it shows only background.
- Sample GLES1 works but I get errors: "E/libEGL (14457): called unimplemented OpenGL ES API"
Asus TF300T (Android 4.2.1):
- Sample GLES2 always shows only background.
- Sample GLES1 also works but I still get errors: "E/libEGL (14457): called unimplemented OpenGL ES API"
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: Ogre 1.8 displays no Entity on Android

Post by Wolfmanfx »

without RTSS you have to provide all shaders thats why i have included it with gles2.
But you do not need to use RTSS write your own shaders and it will work on all devices. The GLES1 error did not happen on my test device i have to address this in the next release.

Also the package i provide use JNI and you do not need to compile any ogre sources you just use it as a lib.
McTwist
Gnoblar
Posts: 2
Joined: Wed Jan 09, 2013 11:53 am

Re: Ogre 1.8 displays no Entity on Android

Post by McTwist »

Zergeny wrote:If you put this code into Java_org_ogre3d_android_OgreActivityJNI_initWindow after creating scene manager:[...]
I am sorry, but first of all I had already added a listener that handled that. Secondly, I added it anyway but it did not work.
Wolfmanfx wrote:Checkout sf.net the precompiled sdk for android *hint* :)
I took everything from there. As you already can see, it did not help. There is also no library there, only dependencies packages. Please elaborate what you mean.
Wolfmanfx wrote:Also the package i provide use JNI and you do not need to compile any ogre sources you just use it as a lib.
I have not located where you provided a library that is already compiled.

Thank you for your support. You have been very helpful, but the problem still persists. I have long since put this project on the side and built my own renderer, which actually works. Therefor, I guess the problem would be that I haven't added a shader for the renderer, but I do know that Ogre uses a default shader if no other exists.
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: Ogre 1.8 displays no Entity on Android

Post by Wolfmanfx »

sbsol
Gnoblar
Posts: 1
Joined: Tue Oct 01, 2013 11:47 am

Re: Ogre 1.8 displays no Entity on Android

Post by sbsol »

Code: Select all

static OgreBites::ShaderGeneratorTechniqueResolverListener*   gMaterialMgrListener;
sorry about the question, but which are the include for that? :P
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre 1.8 displays no Entity on Android

Post by c6burns »

Check the sample browser in your ogre source, or the ogretiny example in this forum. Whatever you are using for development, you should have a way to pattern match within all your code. Otherwise you are going to rely on other people every time you need to find a missing class, etc. Search all your code for ShaderGeneratorTechniqueResolverListener and you will find what you are missing :)
metatomato
Gnoblar
Posts: 2
Joined: Fri Jan 31, 2014 12:00 pm

Re: Ogre 1.9 displays no Entity on Android

Post by metatomato »

Seems that RTSS mess-up with pre-build Android SDK (1.9 RC1) on device supporting GLES 3.0 (nexus 7 2013 edition in my case) throwing an error like : "#version 300 must include es suffix...".

Something related to this topic http://www.ogre3d.org/forums/viewtopic.php?f=2&t=78616.

Had to rebuild the Ogre 1.9 source and Android SDK samples work fine. :D
Post Reply