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:
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,
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,