mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 14:45:39 +00:00
rewrote the fader to use Rectangle2d instead of overlay, in order to not cover the UI
This commit is contained in:
parent
ab698bb401
commit
4829f47a4f
3 changed files with 66 additions and 69 deletions
|
@ -1,52 +1,49 @@
|
||||||
#include "fader.hpp"
|
#include "fader.hpp"
|
||||||
|
|
||||||
#include <OgreOverlayManager.h>
|
|
||||||
#include <OgreOverlayContainer.h>
|
|
||||||
#include <OgreOverlay.h>
|
|
||||||
#include <OgreMaterial.h>
|
#include <OgreMaterial.h>
|
||||||
#include <OgreTechnique.h>
|
#include <OgreTechnique.h>
|
||||||
#include <OgreMaterialManager.h>
|
#include <OgreMaterialManager.h>
|
||||||
#include <OgreResourceGroupManager.h>
|
#include <OgreResourceGroupManager.h>
|
||||||
|
#include <OgreRectangle2D.h>
|
||||||
|
#include <OgreSceneManager.h>
|
||||||
|
|
||||||
#define FADE_OVERLAY_NAME "FadeInOutOverlay"
|
|
||||||
#define FADE_OVERLAY_PANEL_NAME "FadeInOutOverlayPanel"
|
|
||||||
#define FADE_MATERIAL_NAME "FadeInOutMaterial"
|
|
||||||
|
|
||||||
using namespace Ogre;
|
using namespace Ogre;
|
||||||
using namespace OEngine::Render;
|
using namespace OEngine::Render;
|
||||||
|
|
||||||
Fader::Fader() :
|
Fader::Fader(Ogre::SceneManager* sceneMgr)
|
||||||
mMode(FadingMode_In),
|
: mSceneMgr(sceneMgr)
|
||||||
mRemainingTime(0.f),
|
, mMode(FadingMode_In)
|
||||||
mTargetTime(0.f),
|
, mRemainingTime(0.f)
|
||||||
mTargetAlpha(0.f),
|
, mTargetTime(0.f)
|
||||||
mCurrentAlpha(0.f),
|
, mTargetAlpha(0.f)
|
||||||
mStartAlpha(0.f)
|
, mCurrentAlpha(0.f)
|
||||||
|
, mStartAlpha(0.f)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Create the fading material
|
// Create the fading material
|
||||||
MaterialPtr material = MaterialManager::getSingleton().create( FADE_MATERIAL_NAME, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
|
MaterialPtr material = MaterialManager::getSingleton().create("FadeInOutMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
|
||||||
Pass* pass = material->getTechnique(0)->getPass(0);
|
Pass* pass = material->getTechnique(0)->getPass(0);
|
||||||
pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
||||||
mFadeTextureUnit = pass->createTextureUnitState();
|
mFadeTextureUnit = pass->createTextureUnitState();
|
||||||
mFadeTextureUnit->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, ColourValue(0.f, 0.f, 0.f)); // always black colour
|
mFadeTextureUnit->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, ColourValue(0.f, 0.f, 0.f)); // always black colour
|
||||||
|
|
||||||
// Create the overlay
|
mRectangle = new Ogre::Rectangle2D(true);
|
||||||
OverlayManager& ovm = OverlayManager::getSingleton();
|
mRectangle->setCorners(-1.0, 1.0, 1.0, -1.0);
|
||||||
|
mRectangle->setMaterial("FadeInOutMaterial");
|
||||||
|
mRectangle->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY-1);
|
||||||
|
// Use infinite AAB to always stay visible
|
||||||
|
Ogre::AxisAlignedBox aabInf;
|
||||||
|
aabInf.setInfinite();
|
||||||
|
mRectangle->setBoundingBox(aabInf);
|
||||||
|
// Attach background to the scene
|
||||||
|
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
||||||
|
node->attachObject(mRectangle);
|
||||||
|
mRectangle->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
mOverlay = ovm.create( FADE_OVERLAY_NAME );
|
Fader::~Fader()
|
||||||
|
{
|
||||||
OverlayContainer* overlay_panel;
|
delete mRectangle;
|
||||||
overlay_panel = (OverlayContainer*)ovm.createOverlayElement("Panel", FADE_OVERLAY_PANEL_NAME);
|
|
||||||
|
|
||||||
// position it over the whole screen
|
|
||||||
overlay_panel->_setPosition(0, 0);
|
|
||||||
overlay_panel->_setDimensions(1, 1);
|
|
||||||
|
|
||||||
overlay_panel->setMaterialName( FADE_MATERIAL_NAME );
|
|
||||||
overlay_panel->show();
|
|
||||||
mOverlay->add2D(overlay_panel);
|
|
||||||
mOverlay->hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fader::update(float dt)
|
void Fader::update(float dt)
|
||||||
|
@ -69,12 +66,12 @@ void Fader::update(float dt)
|
||||||
mRemainingTime -= dt;
|
mRemainingTime -= dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mCurrentAlpha == 0.f) mOverlay->hide();
|
if (mCurrentAlpha == 0.f) mRectangle->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fader::applyAlpha()
|
void Fader::applyAlpha()
|
||||||
{
|
{
|
||||||
mOverlay->show();
|
mRectangle->setVisible(true);
|
||||||
mFadeTextureUnit->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, mCurrentAlpha);
|
mFadeTextureUnit->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, mCurrentAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,52 +4,52 @@
|
||||||
/*
|
/*
|
||||||
A class that handles fading in the screen from black or fading it out to black.
|
A class that handles fading in the screen from black or fading it out to black.
|
||||||
|
|
||||||
To achieve this, it uses a full-screen Ogre::Overlay
|
To achieve this, it uses a full-screen Rectangle2d
|
||||||
|
|
||||||
inspired by http://www.ogre3d.org/tikiwiki/FadeEffectOverlay (heavily adjusted)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
class TextureUnitState;
|
class TextureUnitState;
|
||||||
class Overlay;
|
class Rectangle2D;
|
||||||
|
class SceneManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace OEngine {
|
namespace OEngine {
|
||||||
namespace Render
|
namespace Render
|
||||||
{
|
{
|
||||||
class Fader
|
class Fader
|
||||||
{
|
|
||||||
public:
|
|
||||||
Fader();
|
|
||||||
|
|
||||||
void update(float dt);
|
|
||||||
|
|
||||||
void fadeIn(const float time);
|
|
||||||
void fadeOut(const float time);
|
|
||||||
void fadeTo(const int percent, const float time);
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum FadingMode
|
|
||||||
{
|
{
|
||||||
FadingMode_In,
|
public:
|
||||||
FadingMode_Out
|
Fader(Ogre::SceneManager* sceneMgr);
|
||||||
|
~Fader();
|
||||||
|
|
||||||
|
void update(float dt);
|
||||||
|
|
||||||
|
void fadeIn(const float time);
|
||||||
|
void fadeOut(const float time);
|
||||||
|
void fadeTo(const int percent, const float time);
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum FadingMode
|
||||||
|
{
|
||||||
|
FadingMode_In,
|
||||||
|
FadingMode_Out
|
||||||
|
};
|
||||||
|
|
||||||
|
void applyAlpha();
|
||||||
|
|
||||||
|
Ogre::TextureUnitState* mFadeTextureUnit;
|
||||||
|
Ogre::Rectangle2D* mRectangle;
|
||||||
|
|
||||||
|
FadingMode mMode;
|
||||||
|
|
||||||
|
float mRemainingTime;
|
||||||
|
float mTargetTime;
|
||||||
|
float mTargetAlpha;
|
||||||
|
float mCurrentAlpha;
|
||||||
|
float mStartAlpha;
|
||||||
|
|
||||||
|
Ogre::SceneManager* mSceneMgr;
|
||||||
};
|
};
|
||||||
|
}}
|
||||||
void applyAlpha();
|
|
||||||
|
|
||||||
Ogre::TextureUnitState* mFadeTextureUnit;
|
|
||||||
Ogre::Overlay* mOverlay;
|
|
||||||
|
|
||||||
FadingMode mMode;
|
|
||||||
|
|
||||||
float mRemainingTime;
|
|
||||||
float mTargetTime;
|
|
||||||
float mTargetAlpha;
|
|
||||||
float mCurrentAlpha;
|
|
||||||
float mStartAlpha;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
};
|
|
||||||
}}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -243,7 +243,7 @@ void OgreRenderer::createScene(const std::string& camName, float fov, float near
|
||||||
// Alter the camera aspect ratio to match the viewport
|
// Alter the camera aspect ratio to match the viewport
|
||||||
mCamera->setAspectRatio(Real(mView->getActualWidth()) / Real(mView->getActualHeight()));
|
mCamera->setAspectRatio(Real(mView->getActualWidth()) / Real(mView->getActualHeight()));
|
||||||
|
|
||||||
mFader = new Fader();
|
mFader = new Fader(mScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OgreRenderer::adjustViewport()
|
void OgreRenderer::adjustViewport()
|
||||||
|
|
Loading…
Reference in a new issue