OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Using PyGame with PyOgre
View page
Source of version: 2
(current)
__Using PyGame with PyOgre__ Original version by [mailto:joshtaylor.mail@gmail.com|Josh Taylor (deficite)] {maketoc} !!PyGame with PyOgre.....why? PyOgre, like C++ OGRE, was not intended as a complete game SDK. Therefore one must find other API's to fill in the gaps (a game is more than just graphics). PyGame is a good choice for this because it provides close to everything PyOgre doesn't. Anything one can do with SDL can be accomplished using PyGame. Check it out at [http://www.pygame.org] !!Getting PyOgre and PyGame to Meld The process of getting PyOgre to render to a PyGame window is quite simple. The trick is simply to tell PyOgre not to create a window but instead use the window PyGame creates: {CODE(wrap="1", colors="python")} def _createWindow(self, width, height, fullscreen): "Creates a PyGame window and sets PyOgre to render onto it" 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 {CODE} !!Complete code example and application class I have provided an application class (which the above code was taken from) to base programs off of or to study: {CODE(wrap="1", colors="python")} # Written by: Josh Taylor (deficite) <joshtaylor.mail@gmail.com> import pygame from pygame.locals import * from pyogre import ogre class PyGameOGREApp: "Provides a base for an application using PyGame and PyOgre" def __init__(self, width=640, height=480, fullscreen=False): self._initPyGame() self._initPyOgre() self._createWindow(width, height, fullscreen) self._createViewport() self._loadResources("resources.cfg") self._createEntities() def _initPyGame(self): "Starts up PyGame" pygame.init() def _initPyOgre(self): "Instantiates the PyOgre root and sceneManager objects and initialises" self.root = ogre.Root("plugins.cfg") self.root.showConfigDialog() self.root.initialise(False) self.sceneManager = self.root.getSceneManager(ogre.ST_GENERIC) def _createWindow(self, width, height, fullscreen): "Creates a PyGame window and sets PyOgre to render onto it" 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 def _createViewport(self): "Creates the user's viewport and camera" self.camera = self.sceneManager.createCamera("camera") self.camera.position = (0, 0, 500) self.camera.lookAt((0, 0, -300)) self.camera.nearClipDistance = 5 self.viewport = self.renderWindow.addViewport(self.camera) self.viewport.backgroundColour = (0, 0, 0) def _loadResources(self, rcfile): "Loads the resource paths from specified resource config file" rc = ogre.ConfigFile() rc.loadFromFile(rcfile) for section, key, path in rc.values: ogre.ResourceGroupManager.getSingleton().addResourceLocation(path, key, section) ogre.ResourceGroupManager.getSingleton().initialiseAllResourceGroups() def _createEntities(self): "For simple demo purposes this can be used to create entities and attach them to sceneNode's" self.entities = [self.sceneManager.createEntity("robot", "robot.mesh")] self.sceneNodes = [self.sceneManager.rootSceneNode.createChildSceneNode("robotNode")] for i in range(len(self.sceneNodes)): self.sceneNodes[i].attachObject(self.entities[i]) def _createScene(self): "Prepare the scene. All logic should go here" pass def _presentScene(self): "Render the scene and anything else needed done at the time of presentation" self.root.renderOneFrame() def run(self): "Brings the application to life" while self._processEvents(): self._createScene() self._presentScene() pygame.quit() def _processEvents(self): "Process events and take appropriate action" for event in pygame.event.get(): if event.type is QUIT: return False elif event.type is KEYDOWN and event.key is K_ESCAPE: return False return True # Instantiate and run! app = PyGameOGREApp() app.run(){CODE} Press escape or the window manager's close button to exit the application.
Search by Tags
Search Wiki by Freetags
Latest Changes
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
...more
Search
Find
Advanced
Search Help
Online Users
105 online users