PDA

View Full Version : Multiple clipping planes



MarvinTau
05-21-2010, 04:07 AM
I don't know how to describe my problem. Perhaps someone's answered my question alreadly. If so, please tell me which post I can refer to, THX.

What happen to me is the clipping planes more than six will have no effect. The default clipping plane defined in gl.h is from GL_CLIP_PLANE0 to GL_CLIP_PLANE5, whose corresponding address are from 0x3000 to 0x3005. And when I assign a plane equation to 0x3006, it has no effect at all.

The openGL documentation says any kind of openGL supports much more than 6 clipping plane. The GL_MAX_CLIP_PLANES also indicates that. But where they are?

#include <stdio.h>
#include <GL/glut.h>

//Just like setup() in Processing. But it doesn't support drawing inside.
//If want to draw a static picture,
void init(int w, int h)
{

float ratio = 1.0 * w / h;

glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45,ratio,1,1000);
}

float angle=0.0;
GLdouble plane0Eq[4] = {0.2, 0.3, 0.4, 0};

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glRotatef(angle,angle,angle,0.0);
glClipPlane(0x3006, plane0Eq);//Change the address here into 0x3000.
glEnable(0x3006);//here

glColor4f(0.2, 0.2, 0.2, 0.4);
glutSolidSphere(1.4, 40, 40);

glDisable(0x3006);//And here
glColor3f(0.3, 0.3, 0.3);
glutWireSphere(1.4, 40, 40);
glDisable(GL_BLEND);
glPopMatrix();

glutSwapBuffers();
angle+=0.1;
}

void changeSize(int w, int h) {

if(h == 0) h = 1;

float ratio = 1.0* w / h;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glViewport(0, 0, w, h);

gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( 0.0, 0.0, 5.0,
0.0, 0.0, -1.0,
0.0f, 1.0f, 0.0f);


}

int main(int argc, char** argv)
{
int width = 300;
int height = 300;

glutInit(&amp;argc,argv); // Passes from ARGC & ARGV
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutInitWindowPosition(100,100);
glutCreateWindow("Clipping");

glutDisplayFunc(display);
glutIdleFunc(display);

glutReshapeFunc(changeSize);
init(width, height);
glutMainLoop();
}

Thank you.

mhagain
05-21-2010, 04:35 AM
Have you reviewed the documentation on clip planes? http://www.opengl.org/sdk/docs/man/xhtml/glClipPlane.xml

Depending on your OpenGL implementation it might be the case that for values greater than 0, if GL_CLIP_PLANEi is enabled then GL_CLIP_PLANE(i - 1) must also be enabled. This should be easily testable. A call to glGetError could also give you useful info on what might be going wrong.

MarvinTau
05-21-2010, 05:24 AM
Thank you, I've read the documentation several times. :(

It doesn't need to enable GL_CLIP_PLANE sequentially in my version of OpenGL. The problem is I cannot enable more than 6 clipping planes. The GL_CLIP_PLANE7 is not defined. And as you suggested, I received GL_INVALID_ENUM when I enable a clipping plane with an undefined address in gl.h, such as 0x3007.

Still waiting for help.