bufferswapping

IchUndNichtDu

07-11-2012 21:29:03

I have wrote a little programm and when i move the camera everything looks a little bit strange because the pictures of the last frames are there for a moment. Now i think i can fix this with buffering and swap the buffers but i don't know something about buffering in ogre. Must i do the buffering myself or do ogre this automatically and if i must do it myself how to buffer and swap the buffers?
I use an auto created window.
I'm Using Python 2.7
I'm using windows 7
I'm using ogre 1.7.2
I hope i described everything right. I'm not very good in english.

dermont

08-11-2012 09:35:55

I have wrote a little programm and when i move the camera everything looks a little bit strange because the pictures of the last frames are there for a moment. Now i think i can fix this with buffering and swap the buffers but i don't know something about buffering in ogre. Must i do the buffering myself or do ogre this automatically and if i must do it myself how to buffer and swap the buffers?
I use an auto created window.
I'm Using Python 2.7
I'm using windows 7
I'm using ogre 1.7.2
I hope i described everything right. I'm not very good in english.


Ogre should automatically swap the buffers when using root.startRendering or root.renderOneFrame with your own loop. You can implement buffer swapping yourself but normally you wouldn't need this for a simple/little program.

Can you upload your program it may be the order/sequence of rendering / camera movement is not as you expect.

IchUndNichtDu

08-11-2012 13:49:01

Here is a for this upload changed version of my cde:
import ogre.renderer.OGRE as ogre
import ogre.io.OIS as OIS

class Player(object):
name = "player"
mesh = "Kubus.mesh"
x = 0
y = 0
z = 0
speed = 0.01

class World(object):
def __init__(self):
self.objects = [Player()]

world = World()

class Application(object):
def __init__(self, player):
assert player in world.objects
self.player = player

def go(self):
self.create_root()
self.define_ressources()
self.choose_rendersystem()
self.create_window()
self.initialise_ressources()
self.scene()
self.start_packages()
self.create_framelistener()
self.start()
self.end()

def create_root(self):
self.root = ogre.Root()

def define_ressources(self):
config = ogre.ConfigFile()
config.load("resources.cfg")
seci = config.getSectionIterator()
while seci.hasMoreElements():
name = seci.peekNextKey()
settings = seci.getNext()
for value in settings:
typ = value.key
path = value.value
ogre.ResourceGroupManager.getSingleton().addResourceLocation(path, typ, name)

def choose_rendersystem(self):
if not self.root.restoreConfig() and not self.root.showConfigDialog():
exit()

def create_window(self):
self.root.initialise(True, "MMORPG")

def initialise_ressources(self):
ogre.TextureManager.getSingleton().setDefaultNumMipmaps(5)
ogre.ResourceGroupManager.getSingleton().initialiseAllResourceGroups()

def scene(self):
self.sceneManager = self.root.createSceneManager(ogre.ST_GENERIC, "Default sceneManager")
i = 0
for thing in world.objects:
name = thing.name + " #%s" % i
entity = self.sceneManager.createEntity(name, thing.mesh)
node = self.sceneManager.getRootSceneNode().createChildSceneNode(name + "-node", (thing.x, thing.y, thing.z))
node.attachObject(entity)
thing.node = node
light = self.sceneManager.createLight("light")
light.type = ogre.Light.LT_POINT
light.position = 0, 400, 400
light.diffuseColour = 1, 1, 1
light.specularColour = 1, 1, 1
self.sceneManager.ambientLight = 1, 1, 1
self.camera = self.sceneManager.createCamera("camera")
self.camera.nearClipDistance = 1
self.camera.farClipDistance= 100000
self.camera.lookAt((0, 0, 0))
self.player.node.attachObject(self.camera)
self.camera.position = 0, 0, 10
viewPort = self.root.getAutoCreatedWindow().addViewport(self.camera)
viewPort.backgroundColour = 0, 0, 0

def start_packages(self):
window = self.root.getAutoCreatedWindow()
windowhandle = window.getCustomAttributeInt("WINDOW")
parameter = [("WINDOW", str(windowhandle))]
self.inputManager = OIS.createPythonInputSystem(parameter)

self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, False)
self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, False)
try:
self.joystick = self.inputManager.createInputObjectJoyStick(OIS.OISJoyStick, False)
except:
self.joystick = None


def create_framelistener(self):
self.control = Control(self, self.keyboard, self.mouse, self.joystick)
self.root.addFrameListener(self.control)

def start(self):
self.root.startRendering()

def end(self):
self.inputManager.destroyInputObjectKeyboard(self.keyboard)
self.inputManager.destroyInputObjectMouse(self.mouse)
if self.joystick:
self.inputManager.destroyInputObjectJoyStick(self.joystick)
OIS.InputManager.destroyInputSystem(self.inputManager)
self.inputManager = None

class Control(ogre.FrameListener, OIS.KeyListener, OIS.MouseListener, OIS.JoyStickListener):
def __init__(self, application, keyboard, mouse, joystick = 0):
ogre.FrameListener.__init__(self)
OIS.KeyListener.__init__(self)
OIS.MouseListener.__init__(self)
OIS.JoyStickListener.__init__(self)
keyboard.setEventCallback(self)
self.keyboard = keyboard
mouse.setEventCallback(self)
self.mouse = mouse
if joystick:
joystick.setEventCallback(self)
self.joystick = joystick
else:
self.joystick = False
self.application = application
self.rotation = 0.1

self.tab = False

def frameStarted(self, frameEvent):
self.keyboard.capture()
self.mouse.capture()

if self.joystick:
self.joystick.capture()

if not self.keyPressed(frameEvent):
return False

self.mouseMoved(frameEvent)

return True


def keyPressed(self, frameEvent):
if self.keyboard.isKeyDown(OIS.KC_ESCAPE):
return False

if self.keyboard.isKeyDown(OIS.KC_W):
self.application.player.node.translate(0, 0, -self.application.player.speed, self.application.player.node.TS_LOCAL)

if self.keyboard.isKeyDown(OIS.KC_S):
self.application.player.node.translate(0, 0, self.application.player.speed, self.application.player.node.TS_LOCAL)

if self.keyboard.isKeyDown(OIS.KC_A):
self.application.player.node.translate(-self.application.player.speed, 0, 0, self.application.player.node.TS_LOCAL)

if self.keyboard.isKeyDown(OIS.KC_D):
self.application.player.node.translate(self.application.player.speed, 0, 0, self.application.player.node.TS_LOCAL)

if self.keyboard.isKeyDown(OIS.KC_TAB):
if not self.tab:
if self.application.camera.position == (0, 0, 0):
self.application.camera.position = 0, 0, 10
else:
self.application.camera.position = 0, 0, 0
self.tab = True
else:
self.tab = False

return True

def mouseMoved(self, frameEvent):
move = self.mouse.getMouseState()
self.application.player.node.yaw(ogre.Degree(move.X.rel).valueRadians() * -self.rotation)
self.application.player.node.pitch(ogre.Degree(move.Y.rel).valueRadians() * -self.rotation)

def __del__(self):
del self.steuerung
del self.root

Application(world.objects[0]).go()

dermont

20-11-2012 16:00:26

Here is a for this upload changed version of my cde:
import ogre.renderer.OGRE as ogre
import ogre.io.OIS as OIS

class Player(object):
name = "player"
mesh = "Kubus.mesh"
x = 0
y = 0
z = 0
speed = 0.01

class World(object):
def __init__(self):
self.objects = [Player()]

world = World()

class Application(object):
def __init__(self, player):
assert player in world.objects
self.player = player

def go(self):
self.create_root()
self.define_ressources()
self.choose_rendersystem()
self.create_window()
self.initialise_ressources()
self.scene()
self.start_packages()
self.create_framelistener()
self.start()
self.end()

def create_root(self):
self.root = ogre.Root()

def define_ressources(self):
config = ogre.ConfigFile()
config.load("resources.cfg")
seci = config.getSectionIterator()
while seci.hasMoreElements():
name = seci.peekNextKey()
settings = seci.getNext()
for value in settings:
typ = value.key
path = value.value
ogre.ResourceGroupManager.getSingleton().addResourceLocation(path, typ, name)

def choose_rendersystem(self):
if not self.root.restoreConfig() and not self.root.showConfigDialog():
exit()

def create_window(self):
self.root.initialise(True, "MMORPG")

def initialise_ressources(self):
ogre.TextureManager.getSingleton().setDefaultNumMipmaps(5)
ogre.ResourceGroupManager.getSingleton().initialiseAllResourceGroups()

def scene(self):
self.sceneManager = self.root.createSceneManager(ogre.ST_GENERIC, "Default sceneManager")
i = 0
for thing in world.objects:
name = thing.name + " #%s" % i
entity = self.sceneManager.createEntity(name, thing.mesh)
node = self.sceneManager.getRootSceneNode().createChildSceneNode(name + "-node", (thing.x, thing.y, thing.z))
node.attachObject(entity)
thing.node = node
light = self.sceneManager.createLight("light")
light.type = ogre.Light.LT_POINT
light.position = 0, 400, 400
light.diffuseColour = 1, 1, 1
light.specularColour = 1, 1, 1
self.sceneManager.ambientLight = 1, 1, 1
self.camera = self.sceneManager.createCamera("camera")
self.camera.nearClipDistance = 1
self.camera.farClipDistance= 100000
self.camera.lookAt((0, 0, 0))
self.player.node.attachObject(self.camera)
self.camera.position = 0, 0, 10
viewPort = self.root.getAutoCreatedWindow().addViewport(self.camera)
viewPort.backgroundColour = 0, 0, 0

def start_packages(self):
window = self.root.getAutoCreatedWindow()
windowhandle = window.getCustomAttributeInt("WINDOW")
parameter = [("WINDOW", str(windowhandle))]
self.inputManager = OIS.createPythonInputSystem(parameter)

self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, False)
self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, False)
try:
self.joystick = self.inputManager.createInputObjectJoyStick(OIS.OISJoyStick, False)
except:
self.joystick = None


def create_framelistener(self):
self.control = Control(self, self.keyboard, self.mouse, self.joystick)
self.root.addFrameListener(self.control)

def start(self):
self.root.startRendering()

def end(self):
self.inputManager.destroyInputObjectKeyboard(self.keyboard)
self.inputManager.destroyInputObjectMouse(self.mouse)
if self.joystick:
self.inputManager.destroyInputObjectJoyStick(self.joystick)
OIS.InputManager.destroyInputSystem(self.inputManager)
self.inputManager = None

class Control(ogre.FrameListener, OIS.KeyListener, OIS.MouseListener, OIS.JoyStickListener):
def __init__(self, application, keyboard, mouse, joystick = 0):
ogre.FrameListener.__init__(self)
OIS.KeyListener.__init__(self)
OIS.MouseListener.__init__(self)
OIS.JoyStickListener.__init__(self)
keyboard.setEventCallback(self)
self.keyboard = keyboard
mouse.setEventCallback(self)
self.mouse = mouse
if joystick:
joystick.setEventCallback(self)
self.joystick = joystick
else:
self.joystick = False
self.application = application
self.rotation = 0.1

self.tab = False

def frameStarted(self, frameEvent):
self.keyboard.capture()
self.mouse.capture()

if self.joystick:
self.joystick.capture()

if not self.keyPressed(frameEvent):
return False

self.mouseMoved(frameEvent)

return True


def keyPressed(self, frameEvent):
if self.keyboard.isKeyDown(OIS.KC_ESCAPE):
return False

if self.keyboard.isKeyDown(OIS.KC_W):
self.application.player.node.translate(0, 0, -self.application.player.speed, self.application.player.node.TS_LOCAL)

if self.keyboard.isKeyDown(OIS.KC_S):
self.application.player.node.translate(0, 0, self.application.player.speed, self.application.player.node.TS_LOCAL)

if self.keyboard.isKeyDown(OIS.KC_A):
self.application.player.node.translate(-self.application.player.speed, 0, 0, self.application.player.node.TS_LOCAL)

if self.keyboard.isKeyDown(OIS.KC_D):
self.application.player.node.translate(self.application.player.speed, 0, 0, self.application.player.node.TS_LOCAL)

if self.keyboard.isKeyDown(OIS.KC_TAB):
if not self.tab:
if self.application.camera.position == (0, 0, 0):
self.application.camera.position = 0, 0, 10
else:
self.application.camera.position = 0, 0, 0
self.tab = True
else:
self.tab = False

return True

def mouseMoved(self, frameEvent):
move = self.mouse.getMouseState()
self.application.player.node.yaw(ogre.Degree(move.X.rel).valueRadians() * -self.rotation)
self.application.player.node.pitch(ogre.Degree(move.Y.rel).valueRadians() * -self.rotation)

def __del__(self):
del self.steuerung
del self.root

Application(world.objects[0]).go()


It is a bit difficult to see where the problem is from the code you posted, things you could try:

a) Add some print statements/change your code/timer toggle in OIS.KC_TAB toggle to see what is happening.

b) Move your Mouse/Keyboard capture to frameRenderingQueued instead of frameStarted.

c) Create an ogre.WindowEventListener not sure if this is a must on Windows but you may encounter similar problems to that reported when resizing the render window.

d) As a first step try simplifying the demo e.g. not attaching the camera to your player.node etc.

For the above check sf_OIS.py that ships with the demos. It would be better if your demo used media from the python-ogre demos.

IchUndNichtDu

20-11-2012 16:42:05

thanks for the answer. i tried not yet but i will.

IchUndNichtDu

23-02-2013 12:00:22

Now i tried onesome of your suggestions
b) Move your Mouse/Keyboard capture to frameRenderingQueued instead of frameStarted.
but i have still the same problem.
a) Add some print statements/change your code/timer toggle in OIS.KC_TAB toggle to see what is happening.
the tab command is temporarily removed for now.
c) Create an ogre.WindowEventListener not sure if this is a must on Windows but you may encounter similar problems to that reported when resizing the render window.
if this even necessary when i don't resize the window? and if yes: what do the WindowListener have to do?
c) Create an ogre.WindowEventListener not sure if this is a must on Windows but you may encounter similar problems to that reported when resizing the render window.
i don't think this is a good idea, because it's going to be a big program/game and someday in the future it has to work with comples constructs anyway.

Now i run this program under Ubuntu12.10 64bit -> same problem
In windowed (non fullscreen mode) the problem doesn't appear.

IchUndNichtDu

23-02-2013 23:49:28

oh now o see that this seems to be a problem of ogre, because in the demos i see the same problem.
sorry for wasting your time.