Overlay Fader OpenGL problem

Zyzle

04-07-2008 15:34:57

I recently converted the code found in this example on the main ogre wiki:
http://www.ogre3d.org/wiki/index.php/FadeEffectOverlay
which produces an overlay which can be used as a fade in/out effect during an app.

I came up with the following code:


class Fader(object):
def __init__(self, overlayName, materialName, instance):
try:
self.fadeop = FADE_NONE
self.alpha = 0.0
self.callbackInstance = instance

material = ogre.MaterialManager.getSingleton().getByName(materialName)

matTechnique = material.getTechnique(0)
matPass = matTechnique.getPass(0)
self.tex_unit = matPass.getTextureUnitState(0)

self.overlay = ogre.OverlayManager.getSingleton().getByName(overlayName)
self.overlay.hide()

except ogre.OgreException:
print "cant __init__"

def startFadeIn(self, duration):
if duration < 0:
duration = -duration

if duration < 0.000001:
duration = 1.0

self.alpha = 1.0
self.total_dur = duration
self.current_dur = duration
self.fadeop = FADE_IN
self.overlay.show()

def startFadeOut(self, duration):
if duration < 0:
duration = -duration
if duration < 0.000001:
duration = 1.0

self.alpha = 0.0
self.total_dur = duration
self.current_dur = 0.0
self.fadeop = FADE_OUT
self.overlay.show()

def fade(self, timeSinceLastFrame):
if self.fadeop is not FADE_NONE and self.tex_unit:
self.tex_unit.setAlphaOperation(ogre.LBX_MODULATE,
ogre.LBS_MANUAL,
ogre.LBS_TEXTURE,
self.alpha)

if self.fadeop is FADE_IN:
self.current_dur -= timeSinceLastFrame
self.alpha = self.current_dur / self.total_dur
#print "alpha ", self.alpha
if self.alpha < 0.0:
self.overlay.hide()
self.fadeop = FADE_NONE
if self.callbackInstance:
self.callbackInstance.fadeInCallback()
elif self.fadeop is FADE_OUT:
self.current_dur += timeSinceLastFrame
self.alpha = self.current_dur / self.total_dur
print "alpha ", self.alpha
if self.alpha > 1.0:
self.fadeop = FADE_NONE
if self.callbackInstance:
self.callbackInstance.fadeOutCallback()


Now I have tested this and it seems to work fine when using the DirectX renderer however if I try to run the code using OpenGL it doesn't work.

When using startFadeIn the screen suddenly flicks to the overlay with no fade transition after the set amount of time, and as best I can tell startFadeOut does nothing.

Is there something wrong with my code or is there something going on at a lower level that I don't know about?

Thanks,

dermont

05-07-2008 08:47:23

Note sure what version of python ogre you are using but the example in the llink you provided above runs fine for me on OpenGL (Linux & Windows). Maybe you should try a different texture or search in the main forum for posts such as:
http://www.ogre3d.org/phpBB2/viewtopic. ... lpha+fader


import sys
sys.path.insert(0,'..')
import PythonOgreConfig

import ogre.renderer.OGRE as ogre
import SampleFramework as sf


class _fadeop():
FADE_NONE, FADE_IN, FADE_OUT = range(3)

class Fader(object):
def __init__(self, overlayName, materialName, instance=None):
self.fadeop = _fadeop.FADE_NONE
self.alpha = 0.0
self.callbackInstance = instance

material = ogre.MaterialManager.getSingleton().getByName(materialName)
matTechnique = material.getTechnique(0)
matPass = matTechnique.getPass(0)
self.tex_unit = matPass.getTextureUnitState(0)
self.overlay = ogre.OverlayManager.getSingleton().getByName(overlayName)
self.overlay.hide()

def startFadeIn(self, duration):
duration = abs(duration)
if duration < 0.000001:
duration = 1.0
self.alpha = 1.0
self.total_dur = duration
self.current_dur = duration
self.fadeop = _fadeop.FADE_IN
self.overlay.show()

def startFadeOut(self, duration):
duration = abs(duration)
if duration < 0.000001:
duration = 1.0
self.total_dur = duration
self.current_dur = 0.0
self.alpha = 0.0

self.fadeop = _fadeop.FADE_OUT
self.overlay.show()

def getCurrentAlpha(self):
return self.alpha

def fade(self, timeSinceLastFrame):

if self.fadeop == _fadeop.FADE_NONE or not self.tex_unit:
return

self.tex_unit.setAlphaOperation(ogre.LBX_MODULATE,
ogre.LBS_MANUAL,
ogre.LBS_TEXTURE,
self.alpha)

if self.fadeop == _fadeop.FADE_IN:
self.current_dur -= timeSinceLastFrame
self.alpha = self.current_dur / self.total_dur
if self.alpha < 0.0:
self.overlay.hide()
self.fadeop = _fadeop.FADE_NONE
if self.callbackInstance:
self.callbackInstance.fadeInCallback()
elif self.fadeop == _fadeop.FADE_OUT:
self.current_dur += timeSinceLastFrame
self.alpha = self.current_dur / self.total_dur
if self.alpha > 1.0:
self.fadeop = _fadeop.FADE_NONE
if self.callbackInstance:
self.callbackInstance.fadeOutCallback()


class CameraTrackApplication(sf.Application):

def __init__(self):
"Init Render Application"
sf.Application.__init__(self)
self.fader = None

def _createScene(self):
sceneManager = self.sceneManager
sceneManager.setAmbientLight ( (0.7, 0.7, 0.7) )
sceneManager.setSkyDome (True, 'Examples/CloudySky',4.0,8.0)

light = sceneManager.createLight('MainLight')
light.setPosition (20, 80, 50)

ogre.ResourceGroupManager.getSingleton().createResourceGroup("Fader")
ogre.ResourceGroupManager.getSingleton().addResourceLocation("./fader",
"FileSystem", "Fader", False)
ogre.ResourceGroupManager.getSingleton().initialiseResourceGroup("Fader")
self.fader = Fader("Overlays/FadeInOut", "Materials/OverlayMaterial")

def cleanUp(self):
del self.fader

def _createFrameListener(self):
self.frameListener = CameraTrackListener(self.renderWindow,
self.camera, self.fader)
self.root.addFrameListener(self.frameListener)

class CameraTrackListener(sf.FrameListener):
def __init__(self, renderWindow, camera, fader):
sf.FrameListener.__init__(self, renderWindow, camera)
self.fader = fader

# def frameRenderingQueued(self, frameEvent):
# t = sf.FrameListener.frameRenderingQueued(self, frameEvent)
# if not t:
# return False
# if self.fader.getCurrentAlpha()<=0.0:
# self.fader.startFadeIn(2.5)
# if self.fader.getCurrentAlpha()>=1.0:
# self.fader.startFadeOut(2.5)
# self.fader.fade(frameEvent.timeSinceLastFrame)
# return True

def frameStarted(self, frameEvent):
t = sf.FrameListener.frameStarted(self, frameEvent)
if not t:
return False
if self.fader.getCurrentAlpha()<=0.0:
self.fader.startFadeOut(2.5)
if self.fader.getCurrentAlpha()>=1.0:
self.fader.startFadeIn(2.5)
self.fader.fade(frameEvent.timeSinceLastFrame)
return True

if __name__ == '__main__':
try:
application = CameraTrackApplication()
application.go()
application.cleanUp()
except ogre.OgreException, e:
print e

Zyzle

05-07-2008 09:46:48

Im using python-ogre 1.1, haven't upgraded to 1.2 yet because I was planning on using OgreODE for physics in my app, although I may change my mind about this.

I should probably have mentioned I'm also running on windows xp, I haven't had a chance to test the code on Linux yet.

Zyzle

06-07-2008 23:06:22

OK quick update, I tested the code on my other PC and it seems to work fine there, I'm wondering if its a dodgy implementation on the (frankly poor) graphics card on my laptop.

Problem solved... I guess.

andy

07-07-2008 01:23:12

This is a problem I see on a regular basis with Laptops and older graphics cards -- and it is all about the underlying graphics driver/hardware (or lack there of)..

Personally I only use the DirectX drivers under Windows..

Andy