红宝书上关于 clipplane 的简单例子.
值得注意的是, clip plane 本身也会受到矩阵变换的影响.
比如 x=0 平面, 表示 x<0 的东西被剪裁掉.
但是,如果在定义这个 clip plane 之前,用了 glTranslatef(-5.0,0,0),x = 0 平面则表示 x<-5 的东西被剪裁掉.
#include <GL/glut.h>
void init()
{
glClearColor( 0.0,0.0,0.0,0.0);
glShadeModel( GL_FLAT );
}
void display()
{
glMatrixMode( GL_MODELVIEW);
glLoadIdentity();
gluLookAt( 0,0,5,0,0,0,0,1,0);
GLdouble eqn[4] = {0.0,1.0,0.0,0.0};
GLdouble eqn2[4] = {1.0,0.0,0.0,0.0};
glPushMatrix();
{
//glTranslatef( -5.0f,0,0);
glClipPlane( GL_CLIP_PLANE0,eqn);
glEnable( GL_CLIP_PLANE0 );
glClipPlane( GL_CLIP_PLANE1,eqn2);
glEnable( GL_CLIP_PLANE1 );
}
glPopMatrix();
glColor3f( 0.5,1.0f,0.2f);
glPushMatrix();
{
glRotatef( 90,1,0,0);
glutWireSphere( 1.0f,30,30);
}
glPopMatrix();
glFlush();
}
void reshape(int w,int h)
{
glViewport( 0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode( GL_PROJECTION);
glLoadIdentity();
gluPerspective( 60.0f,(GLdouble)w/(GLdouble)h,0.1,1000);
}
int main( int argc,char** argv)
{
glutInit( &argc,argv);
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize( 800,600 );
glutInitWindowPosition( 100,100 );
glutCreateWindow("Clip Plane");
glutReshapeFunc( reshape);
glutDisplayFunc( display);
//glutMouseFunc( mousePress);
//glutMotionFunc( mouseMove);
glutMainLoop();
return 0;
}
opengl clip plane
最新推荐文章于 2024-02-10 19:02:34 发布