Ogre in PyGame window example from wiki not working?


07-10-2006 21:27:37

I got the code for rendering Ogre in a PyGame wiki. The code is here:
def _createWindow(self, width, height, fullscreen):
self = pygame.init()
self.screen = pygame.display.set_mode((width,height))
renderParameters = ogre._StringStringMap()
renderParameters['externalWindowHandle'] = str(pygame.display.get_wm_info()['window'])
self.renderWindow = self.root.createRenderWindow('PyOgre through PyGame', width, height, fullscreen, renderParameters)
self.renderWindow.active = True

_createWindow('', width=640, height=480, fullscreen=0)

But it won't work, it just gives me this error:
TypeError: 'tuple' object has only read-only attributes (assign to .screen)

I'm pretty new to Python, so I'm clueless as what to do here. Help please :p


08-10-2006 06:34:51

You should take a look at the "Complete code example and application class", just tried it out and it works fine for me:
http://www.ogre3d.org/wiki/index.php/Us ... ith_PyOgre

You may have to update:

#self.root = ogre.Root("plugins.cfg")
self.root = ogre.Root(ogre.getPluginPath())

# If your using pyogre1.2.0 you'll have to update:
#self.sceneManager = self.root.getSceneManager(ogre.ST_GENERIC)
self.sceneManager = self.root.createSceneManager(ogre.ST_GENERIC)


08-10-2006 12:27:08

It's okay now, I'm using the application class mentioned in another thread & in the wiki. Only problem now is figuring out why it doesn't even show the robot mesh... I don't think it can open zip files :p

EDIT: Yay, the robot's being drawn :D

PyOgre in a PyGame window still seems to run into problems, though... if I do clock.tick(60), which is a PyGame function for keeping the program running in a loop (60 times a second, 60fps), it just seems to lock up drawing of anything on the screen. I can play music as well, but not at the same time :( (I'm using PySonic [FMod wrapper] for the sound)

It seems that it can only do one thing at once, hmm... I'm a newbie to ogre & python in general btw


10-10-2006 11:35:43

def run(self):
"Brings the application to life"
clock = pygame.time.Clock()
running = True

while running:
frametime = clock.tick(60)
running = self._processEvents(frametime)

def _processEvents(self, frametime):
"Process events and take appropriate action"
# more stuff here..

works for me.