Combining Ogre and Python-Ogre

calsmurf2904

28-11-2008 17:06:36

Hello,
I am trying to embed Python-Ogre in my C++ Ogre Application.
The main problem is that Python-Ogre doesn't have the RenderWindows that the C++ Ogre has so that it can't draw on the same Window.
Is there any way to be able to render to the C++ Ogre RenderWindow ?

andy

29-11-2008 00:03:41

Could you expand on what you are doing a little..

I assume you are embedding the python interpreter in your C++ app and then from it loading the ogre.renderer.OGRE module. This would mean that both the ogre module and your C++ app should be linked against a common ogre.lib and using the same OgreMain.dll....

This being the case you should be able to pass the Ogre::Root between C++ and Python and access the same renderWindow etc..

Regards
Andy

calsmurf2904

29-11-2008 12:31:05

something like that....I create the root object etc. in C++ and I am trying to expand the system with PythonOgre for Ingame Scripting.However is PythonOgre able to draw to the renderwindow created in C++ ?
If so how would I do that ? (I am not using Boost.Python....just plain Python Include's)
Also PythonOgre has the Bullet Physics incorperated.....is it also possible to send through Bullet Physics data from C++ to Python Bullet Physics ?

calsmurf2904

29-11-2008 16:38:51

ok...I am currently trying something :

Root* mRoot = new Root(); //Feed this Root to Python ?
//Etc....Initialisation in C++
//Initialisation in Python
PyRun_SimpleString("import ogre.renderer.OGRE as ogre");
PyRun_SimpleString("Root = ogre.Root()");
PyRun_SimpleString("Root.loadPlugin('RenderSystem_Direct3D9_d.dll')");
PyRun_SimpleString("Root.loadPlugin('RenderSystem_GL_d.dll')");
String mCode = "Root.setRenderSystem('" + mRoot->getRenderSystem()->getName() + "')";
PyRun_SimpleString(mCode.c_str());
PyRun_SimpleString("Root.initialise(false)");

It does initialise it
I get this 2 times :

*-*-* OGRE Initialising
*-*-* Version 1.6.0 (Shoggoth)

However I get a black screen...Also it needs to initialise it once.
Is there a Possibility to feed my OgreRoot to PythonOgre ?

andy

30-11-2008 00:57:18

I see your problem and the way to resolve it is to do something like:
Ogre::Root* mRoot = new Root(); //Feed this Root to Python ?
//Etc....Initialisation in C++
//Initialisation in Python
PyRun_SimpleString("import ogre.renderer.OGRE as ogre");
PyRun_SimpleString("Root = ogre.Root.getSingleton()");
...

I'll put together a sample to confirm it all works and post it..

Andy

calsmurf2904

30-11-2008 08:56:39

mmm...thats a great idea....only problem is that I have to recompile PythonOgre with my ogre....however do I need to get the svn version or do I just have to replace the Ogre lib's and includes with my libs and includes and run Setup.py again ?
Nope...that doesn't work.

andy

30-11-2008 10:37:07

No you use the OgreMain.lib etc from the Python Ogre build that are in the PythonOgre/SourceLibs directory...

Andy

calsmurf2904

30-11-2008 11:42:32

mmm...lol...I tried compiling PythonOgre but I needed to first recompile Python with Visual C++ 2008 etc. your solution is much much more simple lol :P....I am going to try it now.
Just to be clear...when PythonOgre and My Program use the same dll's etc. getSingleton returns the singleton used by both ?

andy

30-11-2008 11:48:52

Yes -- use the OgreMain.lib from the SoureLibs directory (you should probably also use the Ogre headers that are there) and then a single OgreMain.dll (the one shipped with PythonOgre) and you'll be fine...

You might want to remove the OgreMain.dll from the \python25\lib\site-packages\ogre\renderer\OGRE directory and stick it in the same directory as your C++ executable just to ensure that only a single copy gets loaded (Windows uses the source path and dll name to determine if it's unique and if you get both loaded nothing will work :) )..

And yes once this is done you can access Singleton's from both C++ and Python..

Regards
Andy

calsmurf2904

30-11-2008 11:51:53

ok...thx for your help...currently redownloading PythonOgre (Removed it lol)
If this all works...I might even give out the code to show how to embed Python with PythonOgre in a C++ Application.(Maybe a Idea for a new wiki article:P)

Edit:
The sourcelibs doesn't include any debug libs...so I can only run the release version ?

calsmurf2904

30-11-2008 13:13:23

mmm...weird...for some kind of reason it is using the same singleton only it doesn't get initialised.So Python thinks that it isn't created and regenerates the singleton wich cause the rendersystem to crash.

calsmurf2904

30-11-2008 16:33:30

ok...compiled correctly against the libs...using the same dll's,includes etc.
well...If I have this code :

int main()
{
try{
...
mRoot->startRendering();
}catch(Ogre::Exception& e)
{
if(WindowCreated) mWindow->destroy();
if(RootCreated) delete mRoot;
cout << e.getFullDescription() << endl;
system("pause");
};
return 0;
};

then it crashes at the return 0; no matter If I use DirectX or OpenGL when I execute the python code :

mRoot = ogre.Root().getSingleton()