converting basic tutorial 8


18-10-2007 22:13:09

Thought i'd be community spirited and try and help converting tutorials on the wiki. I've converted basic tutorial 8 (dual scenemanagers) to python, and it all seems to work, apart from the fact that the skyboxes do not show up when 2 viewports are on-screen at once. It all seems fine, I can see 2 instances of the framerate overlay, and I tried setting a different background color for the second viewport which works fine. Just no geometry or skyboxes. When I switch back to one viewport the skybox re-appears. Heres the code if anyone can help (should just run if you paste into a new file in the demos folder), once it works I'll update the ole wiki!

V switches to dual viewports mode
C should swap the sceneManagers but doesn't seem to work

import ogre.renderer.OGRE as ogre
import as OIS
import SampleFramework as sf

CAMERA_NAME = "SceneCamera"

def setupViewport(RenderWindow, SceneManager):
cam = SceneManager.getCamera(CAMERA_NAME)
vp = RenderWindow.addViewport(cam)
cam.setAspectRatio(vp.getActualWidth() / vp.getActualHeight())

def dualViewport(win, primary, secondary):
secondary.setSkyDome(True, "Examples/CloudySky", 5, 8)
cam = primary.getCamera(CAMERA_NAME)
vp = win.addViewport(cam, 0, 0, 0, 0.5, 1)
cam.setAspectRatio(vp.getActualWidth() / vp.getActualHeight())
cam = secondary.getCamera(CAMERA_NAME)
vp = win.addViewport(cam, 1, 0.5, 0, 0.5, 1)
cam.setAspectRatio(vp.getActualWidth() / vp.getActualHeight())

class SMTutorialListener(sf.FrameListener):
def __init__(self, win, primary, secondary):
sf.FrameListener.__init__(self, win, primary.getCamera(CAMERA_NAME), True, False)
self.mContinue = True
self.mDual = False
self.mWindow = win
self.mPrimary = primary
self.mSecondary = secondary

def frameStarted(self, frameEvent):
return sf.FrameListener.frameStarted(self, frameEvent)

def _processUnbufferedKeyInput(self, frameEvent):
if self.Keyboard.isKeyDown(OIS.KC_V) and self.timeUntilNextToggle <= 0:
self.mDual = not self.mDual
if self.mDual:
dualViewport(self.mWindow, self.mPrimary, self.mSecondary)
setupViewport(self.mWindow, self.mPrimary)

if self.Keyboard.isKeyDown(OIS.KC_C):
self.swap(self.mPrimary, self.mSecondary)
if self.mDual:
dualViewport(self.mWindow, self.mPrimary, self.mSecondary)
setupViewport(self.mWindow, self.mPrimary)

return sf.FrameListener._processUnbufferedKeyInput(self, frameEvent)

def swap(self, first, second):
tmp = first
first = second
second = tmp

class SMTutorialApplication(sf.Application):
def __init__(self):

def _chooseSceneManager(self):
self.mPrimary = ogre.Root.getSingleton().createSceneManager(ogre.ST_GENERIC, "primary")
self.mSecondary = ogre.Root.getSingleton().createSceneManager(ogre.ST_GENERIC, "secondary")

def _createCamera(self):

def _createViewports(self):
setupViewport(self.renderWindow, self.mPrimary)

def _createScene(self):
self.mPrimary.setSkyBox(True, "Examples/SpaceSkyBox")
self.mSecondary.setSkyDome(True, "Examples/CloudySky", 5, 8)

def _createFrameListener(self):
self.mFrameListener = SMTutorialListener(self.renderWindow, self.mPrimary, self.mSecondary);

if __name__ == '__main__':
app = SMTutorialApplication()


19-10-2007 08:12:54


cam.setAspectRatio(float(vp.getActualWidth()) / float(vp.getActualHeight()))

Also you could maybe add a time toggle to the viewport switch:

if self.Keyboard.isKeyDown(OIS.KC_V) and self.timeUntilNextToggle <= 0:
self.timeUntilNextToggle = 1

And if your wiking this you should make sure the demo shuts down cleanly.


19-10-2007 09:06:16

thanks dermont,

that fixes the problem. Its strange, on my home pc it does shut down cleanly, but having just tried it on another pc i get an error on close. Will sort that before wikiing


19-10-2007 09:21:13

ok, its done and seems to be working perfectly now, yippee! haven't noticed any errors now ( overridden the __del__ method to get rid of both sceneManagers, and the C key now swaps them properly)

will update the wiki sometime today, and perhaps crack on with another