I am in the need of backporting some OpenGL 3.x code using GL_CLIP_DISTANCEx to GL 2.x with no shaders, but of course, without the ability to use shaders I have to resort to the old way of defining clip planes.
The only problem is, I cannot find any documentation how I have to calculate the plane equations. No documentation I have seen so far goes any further than the absolute basics.
Basically I have two use cases:
Case 1: An y-coordinate in world coordinates is specified, and clip everything whose y is either greater or less.
Case 2: I have a full plane equation in world coordinates and need to transform this to eye coordinates.
How can I do that?
In which case, the plane coefficients will be either [0,1,0,Y] or [0,-1,0,-Y] depending upon which side of the plane is the “inside”.
If you want to specify a plane in “world” coordinates, set the model-view matrix to “world” coordinates prior to calling glClipPlane(). The plane passed to glClipPlane() is transformed by the current model-view matrix and the resulting plane (in eye coordinates) is stored and used for clipping. Subsequent changes to the model-view matrix have no effect.
Still doesn’t work. Here’s the code to set it up. glEnable and glDisable are called elsewhere as needed:
if (gl.glslversion < 1.3f)
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadMatrixf(mViewMatrix.get());
double d[4] = { 0, direction, 0, -direction * height };
glClipPlane(GL_CLIP_PLANE0, d);
glPopMatrix();
}