Page 1 of 1

draw to viewport getting clipped

Posted: Tue Apr 21, 2009 9:45 am
by gheft
Hi,
so I am trying to get a custom GUI button working similar to this compass by vitek http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=16887

problem is, I put this on a bar that scrolls across the bottom of the screen, if the button goes past the edge of the screen, it is clipped against the screen, so it gets squeezed against the side of the screen and then fills up the entire screen if it goes completely outside the screen.
I think it is driver->setViewPort(AbsoluteRect); that clips it.
So I'm trying to do this instead by setting the mesh vertices to the rectangle position but I'm not sure what to set the transforms (ETS_VIEW etc.) to, to just draw a simple rectangle mesh.
Any suggestions?

Posted: Tue Apr 21, 2009 9:56 am
by BlindSide
This may help:
http://irrlicht.sourceforge.net/phpBB2/ ... 077#183077

Although the aspect ratio is wrong, you may need to change the part "setTransform(ETS_PROJECTION, ... )" to accept a projection matrix with an aspect ratio of ScreenSize.height / ScreenSize.width.

Posted: Mon Apr 27, 2009 8:25 am
by gheft
yessss finally got it working, Thanks Blindside :D

heres the alternative to changing the view port

recti vp = driver->getViewPort();
recti mRect = meshRect - vector2di(vp.getWidth(),vp.getHeight())/2;

mRect.LowerRightCorner.Y *= -1;
mRect.UpperLeftCorner.Y *= -1;

Mesh.Vertices[0].Pos.X = mRect.UpperLeftCorner.X;
Mesh.Vertices[0].Pos.Y = mRect.LowerRightCorner.Y;
Mesh.Vertices[3].Pos.X = mRect.LowerRightCorner.X;
Mesh.Vertices[3].Pos.Y = mRect.LowerRightCorner.Y;
Mesh.Vertices[2].Pos.X = mRect.LowerRightCorner.X;
Mesh.Vertices[2].Pos.Y = mRect.UpperLeftCorner.Y;
Mesh.Vertices[1].Pos.X = mRect.UpperLeftCorner.X;
Mesh.Vertices[1].Pos.Y = mRect.UpperLeftCorner.Y;

matrix4 ProjMatrix;
ProjMatrix.buildProjectionMatrixOrthoLH(vp.getWidth(),vp.getHeight(), -100.0f, 1000.0f);
driver->setTransform(ETS_PROJECTION, ProjMatrix);
driver->setTransform(ETS_VIEW, matrix4());
driver->setTransform(ETS_WORLD, matrix4());

driver->setMaterial(Mesh.Material);
driver->drawMeshBuffer(&Mesh);