首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

OpenGL裁剪平面的有关问题

2012-03-08 
OpenGL裁剪平面的问题这是我的一个使用了2个裁剪平面的例子,代码:C/C++ code#include GL/glut.h#include

OpenGL裁剪平面的问题
这是我的一个使用了2个裁剪平面的例子,代码:

C/C++ code
#include <GL/glut.h>#include <iostream>using namespace std;void init(void) {   glClearColor (0.0, 0.0, 0.0, 0.0);   glShadeModel (GL_FLAT);}void display(void){   GLdouble eqn[4] = {0.0, 1.0, 0.0, 0.0};   GLdouble eqn2[4] = {1.0, 0.0, 0.0, 0.0};   glClear(GL_COLOR_BUFFER_BIT);   glColor3f (1.0, 1.0, 1.0);   glPushMatrix();   glTranslatef (0.0, 0.0, -5.0);   glRotatef (90.0, 1.0, 0.0, 0.0);   /*    clip lower half -- y < 0          */   glClipPlane (GL_CLIP_PLANE0, eqn);   glEnable (GL_CLIP_PLANE0);      /*    clip left half -- x < 0           */   glClipPlane (GL_CLIP_PLANE1, eqn2);   glEnable (GL_CLIP_PLANE1);   glutWireSphere(1.0, 20, 16);   glPopMatrix();   glFlush ();}void reshape (int w, int h){   glViewport (0, 0, (GLsizei) w, (GLsizei) h);    glMatrixMode (GL_PROJECTION);   glLoadIdentity ();   gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);   glMatrixMode (GL_MODELVIEW);}void keyboard(unsigned char key, int x, int y){   switch (key) {      case 27:         exit(0);         break;   }}int main(int argc, char** argv){   glutInit(&argc, argv);   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);   glutInitWindowSize (500, 500);    glutInitWindowPosition (100, 100);   glutCreateWindow (argv[0]);   init ();   glutDisplayFunc(display);    glutReshapeFunc(reshape);   glutKeyboardFunc(keyboard);   glutMainLoop();   return 0;}


这是运行后的结果:

奇怪,经过2次剪切之后不是应该只能看到1/4个球体吗?为什么会这样子?
求指导!!感激不尽!

[解决办法]
glRotatef (90.0, 1.0, 0.0, 0.0); 放到glEnable (GL_CLIP_PLANE1);后

热点排行