[1.8.3; OpenGL] "moving" Clipping Planes

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
GrafZahl
Posts: 37
Joined: Mon Oct 20, 2014 6:24 pm

[1.8.3; OpenGL] "moving" Clipping Planes

Post by GrafZahl »

Hello

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);
 
(to make the example easy, I just copied the Left Clipping plane to it)

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 before the setup of Projection and Modelview matrix for 2D, then the clipping plane will move around the screen dependent on the rotation of the last 3D object. I think this is because the clipping plane is applied relatively to the matrices of the rotating object.
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
Irrlicht related projects:
Looking for a cool and easy to use GUI? Try the IrrIMGUI bindings for IMGUI: https://github.com/ZahlGraf/IrrIMGUI
Try out my Irrlicht CMake build system: https://github.com/ZahlGraf/IrrlichtCMake
Post Reply