Table of contents


This is a really sparse example based on the Practical Application tutorial by Gregory Junker. I haven't used his exact structure, but you will be able to achieve the same thing, which is to start OGRE without the configuration dialog popping up.


import pyogre.ogre as ogre

class testApp( object ):
    def __init__( self ):
        self.root = ogre.Root( ogre.getPluginPath() )

        self.root.initialise( False )
        self.window = self.root.createRenderWindow( "PyOgreWindow", 640, 480, False )
        self.sceneManager = self.root.getSceneManager( ogre.ST_GENERIC )
        = self.sceneManager.createCamera( "PlayerCam" ) = (0, 0, 500), 0, -300)) = 5
        self.viewport = self.window.addViewport( )
        self.viewport.backgroundColour = (0, 0, 0)

        ogre.TextureManager.getSingleton().defaultNumMipmaps = 5

        # create the scene
        # add a frameListener for input etc, off you go

    def _initResources( self ):        
        "Set resource group paths."
        # Set up resource paths
        configFile = ogre.ConfigFile()
        configFile.loadFromFile( "resources.cfg" )
        # File format is:
        #  [ResourceGroupName]
        #  ArchiveType=Path
        #  .. repeat
        # For example:
        #  [General]
        #  FileSystem=media/
        #  Zip=packages/
        for section, key, path in configFile.values:
            ogre.ResourceGroupManager.getSingleton().addResourceLocation( path, key, section )

    def _configure( self ):
        Examine config options and set OGRE options accordingly.
        For now we're going to hard-code the settings just to prove the concept.
        renList = self.root.getAvailableRenderers()
        for r in renList:
            if "OpenGL" ):
                self.root.renderSystem = r
        print "OpenGL renderer not found!"

if __name__ == "__main__":
    ta = testApp()


It will look for "resources.cfg" in the same directory as the .py file. (This is true on Windows, at least. Other platforms might not behave the same way, so you may need to tell Python the path to the current directory.)

Obviously this could be expanded a lot, modularized, and generally made more flexible (especially the _configure() function). But the point of this was to do things in a straight-forward manner in order to learn quickly.

-by Jason, from Grim Inventions Interactive