today i finished my classes to create any controls using cegui , now i want to create effect like demo7 ( OK .... the same effect )
so i read to source code and i copy the same effect to my project to test it ,
i understand that the effect must be the same RenderEffect class ( members and functions ),
and the effect must registered at the system like this
Code: Select all
RenderEffectManager::getSingleton().addEffect<MyEffect> ( "EFFECTTEST");
i run the application but my window has no effect even if i move it .
i think i need to call
function in my loop to apply the effect ..........is that true ??!update
if yes ; what i should pass in RenderingWindow parameters , i try to pass Framewindow but i get error
excuse me but i am bad understand this RenderingWindow class , any help
the source code
Code: Select all
class MyEffect : public CEGUI::RenderEffect
{
public:
MyEffect();
// implement required functions from RenderEffect interface.
int getPassCount() const;
void performPreRenderFunctions(const int pass);
void performPostRenderFunctions();
bool realiseGeometry(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry);
bool update(const float elapsed, CEGUI::RenderingWindow& window);
protected:
static const float tess_x;
static const float tess_y;
// tess_x * tess_y * vertex_per_quad
static const int buffsize = (16 * 16 * 6);
bool initialised;
float lastX, lastY;
float dragX, dragY;
float elasX, elasY;
CEGUI::Vertex vb[buffsize];
};
const float MyEffect::tess_x = 12;
const float MyEffect::tess_y = 12;
//----------------------------------------------------------------------------//
MyEffect::MyEffect() :
initialised(false),
dragX(0), dragY(0),
elasX(0), elasY(0)
{
}
//----------------------------------------------------------------------------//
int MyEffect::getPassCount() const
{
return 1;
}
//----------------------------------------------------------------------------//
void MyEffect::performPreRenderFunctions(const int /*pass*/)
{
// nothing we need here
}
//----------------------------------------------------------------------------//
void MyEffect::performPostRenderFunctions()
{
// nothing we need here
}
//----------------------------------------------------------------------------//
bool MyEffect::realiseGeometry(CEGUI::RenderingWindow& window,
CEGUI::GeometryBuffer& geometry)
{
using namespace CEGUI;
Texture& tex = window.getTextureTarget().getTexture();
static const CEGUI::colour c(1, 1, 0, 1);
const float qw = window.getSize().d_width / tess_x;
const float qh = window.getSize().d_height / tess_y;
const float tcx = qw * tex.getTexelScaling().d_x;
const float tcy =
(window.getTextureTarget().isRenderingInverted() ? -qh : qh) *
tex.getTexelScaling().d_y;
for (int j = 0; j < tess_y; ++j)
{
for (int i = 0; i < tess_x; ++i)
{
int idx = (j * tess_x + i) * 6;
float top_adj = dragX * ((1.0f / tess_x) * j);
float bot_adj = dragX * ((1.0f / tess_x) * (j+1));
top_adj = ((top_adj*top_adj) / 3) * (dragX < 0 ? -1 : 1);
bot_adj = ((bot_adj*bot_adj) / 3) * (dragX < 0 ? -1 : 1);
float lef_adj = dragY * ((1.0f / tess_y) * i);
float rig_adj = dragY * ((1.0f / tess_y) * (i+1));
lef_adj = ((lef_adj*lef_adj) / 3) * (dragY < 0 ? -1 : 1);
rig_adj = ((rig_adj*rig_adj) / 3) * (dragY < 0 ? -1 : 1);
// vertex 0
vb[idx + 0].position = Vector3(i * qw - top_adj, j * qh - lef_adj, 0.0f);
vb[idx + 0].colour_val = c;
vb[idx + 0].tex_coords = Vector2(i * tcx, j*tcy);
// vertex 1
vb[idx + 1].position = Vector3(i * qw - bot_adj, j * qh + qh - lef_adj, 0.0f);
vb[idx + 1].colour_val = c;
vb[idx + 1].tex_coords = Vector2(i*tcx, j*tcy+tcy);
// vertex 2
vb[idx + 2].position = Vector3(i * qw + qw - bot_adj, j * qh + qh - rig_adj, 0.0f);
vb[idx + 2].colour_val = c;
vb[idx + 2].tex_coords = Vector2(i*tcx+tcx, j*tcy+tcy);
// vertex 3
vb[idx + 3].position = Vector3(i * qw + qw - bot_adj, j * qh + qh - rig_adj, 0.0f);
vb[idx + 3].colour_val = c;
vb[idx + 3].tex_coords = Vector2(i*tcx+tcx, j*tcy+tcy);
// vertex 4
vb[idx + 4].position = Vector3(i * qw + qw - top_adj, j * qh - rig_adj, 0.0f);
vb[idx + 4].colour_val = c;
vb[idx + 4].tex_coords = Vector2(i*tcx+tcx, j*tcy);
// vertex 5
vb[idx + 5].position = Vector3(i * qw - top_adj, j * qh - lef_adj, 0.0f);
vb[idx + 5].colour_val = c;
vb[idx + 5].tex_coords = Vector2(i * tcx, j*tcy);
}
}
geometry.setActiveTexture(&tex);
geometry.appendGeometry(vb, buffsize);
// false, because we do not want the default geometry added!
return false;
}
//----------------------------------------------------------------------------//
bool MyEffect::update(const float elapsed, CEGUI::RenderingWindow& window)
{
using namespace CEGUI;
// initialise ourself upon the first update call.
if (!initialised)
{
initialised=true;
lastX = window.getPosition().d_x;
lastY = window.getPosition().d_y;
return true;
}
const Vector2 pos(window.getPosition());
//
// Set up for X axis animation.
//
if (pos.d_x != lastX)
{
dragX += (pos.d_x - lastX) * 0.2;
elasX = 0.05f;
lastX = pos.d_x;
if (dragX > 25)
dragX = 25;
else if (dragX < -25)
dragX = -25;
}
//
// Set up for y axis animation
//
if (pos.d_y != lastY)
{
dragY += (pos.d_y - lastY) * 0.2f;
elasY = 0.05f;
lastY = pos.d_y;
if (dragY > 25)
dragY = 25;
else if (dragY < -25)
dragY = -25;
}
//
// Perform required animation steps
//
if ((dragX != 0) || (dragY != 0))
{
if (dragX < 0)
{
dragX += (elasX * 800 * elapsed);
elasX += 0.075 * elapsed;
if (dragX >0)
dragX = 0;
}
else
{
dragX -= (elasX * 800 * elapsed);
elasX += 0.075 * elapsed;
if (dragX < 0)
dragX = 0;
}
if (dragY < 0)
{
dragY += elasY * 800 * elapsed;
elasY += 0.075 * elapsed;
if (dragY >0)
dragY = 0;
}
else
{
dragY -= elasY * 800 * elapsed;
elasY += 0.075 * elapsed;
if (dragY < 0)
dragY = 0;
}
// note we just need system to redraw the geometry; we do not need a
// full redraw of all window/widget content - which is unchanged.
System::getSingleton().signalRedraw();
return false;
}
return true;
}