Converting Tutorials on the Wiki


21-10-2007 15:00:13

Hi everyone.

I reasonably new to both Ogre and Python, but I'm working my way through both and going through the tutorials I noticed that a few of them are still C++ format on the python-ogre wiki page.

Are there any objections to me converting some of them as I go through them? I might not be right person to convert them, since I both new to Ogre and Python, but perhaps someone can still learn from it?

I have converted one so far, the Intermediate Tutorial #1, on Animation. ... Tutorial_1

It runs, but if I did anything thats not best practice, please correct me, or just revert the page back to the C++ version :-)


21-10-2007 16:18:48

Actually I think converting tutorials from one language to another is a pretty good way to learn either a language, or a system, or both. The only problem is what you end up with is probably going to look a lot like C++ code which was converted to python; but with python-ogre it's kind of hard to avoid that anyway :)

From my quick test, the code at least works, so good job on that.

One complaint, on firefox the the questions at the end extend beyond the box to the right making the page extremely wide.

On second thought, it seems that is a problem on all of the pages - something to do with PyWiki itself. It's because of the <pre></pre> tags I think. I converted the questions to numbered lists without the <pre> using #'s. Another option would be to keep the <pre> and add some returns to make the lines not so long.

Anyway thanks for taking this on. When I was learning I skipped the intermediate tutorials because they weren't in python.


21-10-2007 17:54:37

One complaint, on firefox the the questions at the end extend beyond the box to the right making the page extremely wide.

I converted the questions to numbered lists without the pre using #'s. Another option would be to keep the pre and add some returns to make the lines not so long.

Ah, yes, I saw that too. I don't know why they were in between pre tags. I was about to look up the wiki syntax for numbered lists but then got sidetracked :).


21-10-2007 21:54:44

Cool, I was going to tackle that one next!

which of the other intermediates are you planning to convert? tell me and I will try and do the rest :)


22-10-2007 11:00:31

I was planning on going on to the next one and do them in order, but I'm stuck on Intermediate Tutorial #2. My framelistener keeps on throwing an exception about calling a NoneType in FrameStarted after adding multiple inheritance to it and adding OIS.MouseListener.

I'm not sure if this even the right way of doing it with Python, I was just following with the C++ example.

I'm at work now so can't post the code here, but if you can get it working, please go ahead and convert it :).


24-10-2007 01:24:07

To improve the wiki I added syntax highlighting support. For code sections you enclose them like:

<source lang="python">
code goes here

By doing this you don't need the leading space in the code section. The quotes are needed around the "language".



24-10-2007 22:58:52

Thanks Andy, that will help a lot. It was a bit of a pain inserting those spaces in the examples :).

I will probably continue converting the tutorials once I get more experience with PythonOgre. There is still a lot I have to learn!


27-10-2007 18:17:29

It's nice to see work being done on the wiki. One of the main reasons I stopped tinkering with pyOgre several months ago was lack of documentation or tutorials in an easy to follow format.

I'd be willing to lend a hand in converting some of these tutorials too, if that's okay. I noticed that several of the basic ones aren't converted, so I might try those.

Edit: I noticed that Intermediate 4 suffers from these major problems:

1. The "initial code" at the beginning is actually the entirety of the code, after the incremental process is already done.
2. The parts he tells you to "add" (even though you can't, see #1) are in C++!
3. It doesn't even work! :P

I'm in the process of fixing it up right now, and I'm learning quite a bit about the input system while doing it. Win-win.


27-10-2007 23:16:25

yeahm that was my fault -- I was sent code showing a bug and got confused and thought it was the completed demo code..

You'll find lots of others issues in the Wiki, however all easy to fix :)



28-10-2007 01:25:28

I finished fixing it up, and the code works now too.

Edit: Going to start working on basic tutorial 6, the one where you don't have to use SampleFramework. I'm interested in this one quite a bit. Is there a sort of aggregate place that lists who's planning to do what on the wiki?


28-10-2007 23:48:45

OgreCEGUIRenderer is now crashing python-ogre, at this code:

sceneManager = self.root.getSceneManager("Default SceneManager")
renderWindow = self.root.getAutoCreatedWindow()
self.renderer = CEGUI.OgreCEGUIRenderer(renderWindow, ogre.RENDER_QUEUE_OVERLAY, False, 3000, sceneManager)

I know the problem is in the third line; the SceneManager and RenderWindow have been working fine for a long time, so I don't think it's them. I'm just porting the code from the tutorial, so I don't know if there's a better class to use now or anything.

Anyone know what the deal could be? (No error, just a crash.)


29-10-2007 05:13:42

Don't think you problem is in the above line, I'm guessing here that you may be passing a Null/None to CEGUI.System, e.g:

self.renderer = CEGUI.OgreCEGUIRenderer(renderWindow, ogre.RENDER_QUEUE_OVERLAY, False, 3000, sceneManager)
self.mSystem = CEGUI.System(self.mRenderer)

Anyway here's an example of the tutorial:

import ogre.renderer.OGRE as ogre
import as OIS
import ogre.gui.CEGUI as cegui

class ExitListener(ogre.FrameListener):

def __init__(self, keyboard):
self.mKeyboard = keyboard

def frameStarted(self, evt):
return not self.mKeyboard.isKeyDown(OIS.KC_ESCAPE)

class Application(object):

def __init__(self):
self.mRoot = None
self.mKeyboard = None
self.mInputManager = None
self.mRenderer = None
self.mSystem = None
self.mListener = None

def __del__(self):
del self.mSystem
del self.mRenderer
del self.mListener
del self.mRoot

def go(self):

def cleanUp(self):

def createRoot(self):
self.mRoot = ogre.Root()

def defineResources(self):
"""This sets up Ogre's resources, which are required to be in

config = ogre.ConfigFile()
config.load('resources.cfg' )
seci = config.getSectionIterator()
while seci.hasMoreElements():
SectionName = seci.peekNextKey()
Section = seci.getNext()
for item in Section:
addResourceLocation(item.value, item.key, SectionName)

def setupRenderSystem(self):

if (not self.mRoot.restoreConfig() and not self.mRoot.showConfigDialog()):
raise ogre.Exception(52, "User canceled the config dialog!", "Application::setupRenderSystem()")

#### Do not add this to the application
##rs = self.mRoot.getRenderSystemByName("Direct3D9 Rendering Subsystem")
##rs.setConfigOption("Full Screen", "No")
##rs.setConfigOption("Video Mode", "800 x 600 @ 32-bit colour")

def createRenderWindow(self):
self.mRoot.initialise(True, "Tutorial Render Window")

def initializeResourceGroups(self):

def setupScene(self):

mgr = self.mRoot.createSceneManager(ogre.ST_GENERIC, "Default SceneManager")
cam = mgr.createCamera("Camera")
vp = self.mRoot.getAutoCreatedWindow().addViewport(cam)

## ========================
## Other OGRE setup here.
## ========================
if 1==1:
mgr.setAmbientLight ( (0.9, 0.9, 0.9) )
cam.setPosition(ogre.Vector3(0, 0, 500))
cam.lookAt(ogre.Vector3(0, 0, -300))
cam.NearClipDistance = 5

headNode = mgr.getRootSceneNode().createChildSceneNode()
entity = mgr.createEntity('head', 'ogrehead.mesh')

def setupInputSystem(self):

win = self.mRoot.getAutoCreatedWindow()
windowHnd = win.getCustomAttributeInt("WINDOW")
self.mInputManager = OIS.createPythonInputSystem([ ( "WINDOW",
self.mKeyboard = self.mInputManager.createInputObjectKeyboard( OIS.OISKeyboard, False )

def setupCEGUI(self):

mgr = self.mRoot.getSceneManager("Default SceneManager")
win = self.mRoot.getAutoCreatedWindow()

## CEGUI setup
self.mRenderer = cegui.OgreCEGUIRenderer(win, ogre.RENDER_QUEUE_OVERLAY, False, 3000, mgr)
self.mSystem = cegui.System(self.mRenderer)

## ========================
## Other CEGUI setup here.
## ========================
if 1==1:
### load TaharezLook scheme
self.mSystem.setDefaultMouseCursor("TaharezLook", "MouseArrow")
sheet = cegui.WindowManager.getSingleton().createWindow("DefaultWindow", "root_wnd")
self.mSystem.setGUISheet (sheet)
window = cegui.WindowManager.getSingleton().createWindow( "TaharezLook/FrameWindow", "TESTFRAME")
window.setSize(cegui.UVector2( cegui.UDim(0.3,0),
cegui.UDim(0.3,0)) )
window.setText("New Window")

def createFrameListener(self):
self.mListener = ExitListener(self.mKeyboard)

def startRenderLoop(self):

if __name__ == '__main__':
ta = Application()
except ogre.OgreException, e:
print e


29-10-2007 18:08:16

Thanks for the *working* code, I updated my code on the tutorial so it actually works this time. Is there a document that shows Ogre API changes from C++ to Python?


29-10-2007 19:25:11

If there isn't one, we should probably create a Wiki page.


31-10-2007 06:16:06

Just finished basic tutorial 7.

Here are the ones I've done so far:
Basic Tutorial 6: The Ogre Startup Sequence
Basic Tutorial 7: CEGUI and Ogre
Intermediate Tutorial 4: Volume Selection and Basic Manual Objects


01-11-2007 01:52:41

Many thanks for all your work on this -- the docuementation is starting to be real !!!!!! :)



28-03-2009 15:48:57

I hate to dredge up a topic from so long ago, but is anyone interested in really starting to flesh out the documentation? I've just come back to Python-Ogre after all this time and was disappointed to see the wiki still so... barren. I think we should try to make it mirror the OGRE wiki as closely as possible.