I think I found an issue in Irrlicht that is related to clipping planes.
After drawing my 3D scene, I use the function "draw2DVertexPrimitiveList" to draw GUI elements to the screen. For this GUI elements I need some kind of scissoring (Scissor test or something like that). However this is not supported by that function.
Thus I just use 4 clipping planes to emulate the Scissor Test.
This means before I call "draw2DVertexPrimitiveList", I have some code like that:
Code: Select all
irr::core::plane3df LeftPlane(irr::core::vector3df(1.0f, 0.0f, 0.0f), -pDrawCommand->ClipRect.x);
pIrrDriver->setClipPlane(0, LeftPlane, true);
// draw something with draw2DVertexPrimitiveList
pIrrDriver->enableClipPlane(0, false);
This works quite good, except for the very first GUI element, that is drawn by "draw2DVertexPrimitiveList", because here the clipping plane is moving around the screen (it moves slowly from the left side to the right side of the screen).
In my 3D scene there is a 3D object that rotates and this object is the last 3D object that is drawn before I start with the 2D GUI. When I stop the rotation, the clipping plane is also stable and will not move.
I looked inside the OpenGL driver implementation of Irrlicht and found the function "setRenderStates2DMode". Inside this function the matrices will be adapted for 2D drawing when the last rendered object was a 3D object (so it switched into 2D mode).
I just added some OpenGL testcode for clipping:
Code: Select all
double DoubleArray[4] = {1.0f, 0.0f, 0.0f, -100.f};
glClipPlane(GL_CLIP_PLANE0, DoubleArray);
glEnable(GL_CLIP_PLANE0);
When I add this after the setup of Projection and Modelview matrix, the clipping plane is stable and will not move.
So my theory is that applying the clipping planes directly when the user calls "setClipPlane" is wrong. Because then clipping planes are applied with matrix settings that belong to the last rendered object. However the user expects that clipping planes will be applied with the matrix settings for the next object to render.
Unfortunately this seems to be a bigger code change.
As a workaround in my case, I can simply draw a simple 2D object, that is not visible to the user, before I apply the first clipping plane. In this way I can ensure, that the matrices are already prepared for 2D operation.
Best regards,
Graf Zahl