History: PyOgre Without Configuration Dialog
Source of version: 2 (current)
Copy to clipboard
{maketoc}
!!Intro
This is a really sparse example based on the [http://www.ogre3d.org/wiki/index.php/Practical_Application|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.
!!Code
{CODE(wrap="1", colors="python")}import pyogre.ogre as ogre
class testApp( object ):
def __init__( self ):
self.root = ogre.Root( ogre.getPluginPath() )
self._initResources()
self._configure()
self.root.initialise( False )
self.window = self.root.createRenderWindow( "PyOgreWindow", 640, 480, False )
self.sceneManager = self.root.getSceneManager( ogre.ST_GENERIC )
self.camera = self.sceneManager.createCamera( "PlayerCam" )
self.camera.position = (0, 0, 500)
self.camera.lookAt((0, 0, -300))
self.camera.nearClipDistance = 5
self.viewport = self.window.addViewport( self.camera )
self.viewport.backgroundColour = (0, 0, 0)
ogre.TextureManager.getSingleton().defaultNumMipmaps = 5
ogre.ResourceGroupManager.getSingleton().initialiseAllResourceGroups()
# 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/level1.zip
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:
#print r.name
if r.name.startswith( "OpenGL" ):
self.root.renderSystem = r
return
print "OpenGL renderer not found!"
if __name__ == "__main__":
ta = testApp(){CODE}
!!Discussion
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 [http://www.griminventions.com|Grim Inventions Interactive]