Opengl Hemisphere内表面

时间:2012-04-22 19:48:02

标签: c++ opengl geometry

我想尝试创建一个Hemi-Sphere。

这是我的代码

void drawHalfSphere(int scaley, int scalex, GLfloat r) {
int i, j;
GLfloat v[scalex*scaley][3];

for (i=0; i<scalex; ++i) {
 for (j=0; j<scaley; ++j) {
    v[i*scaley+j][0]=r*cos(j*2*M_PI/scaley)*cos(i*M_PI/(2*scalex));
    v[i*scaley+j][1]=r*sin(i*M_PI/(2*scalex));
    v[i*scaley+j][2]=r*sin(j*2*M_PI/scaley)*cos(i*M_PI/(2*scalex));
 }
}

glBegin(GL_QUADS);
for (i=0; i<scalex-1; ++i) {
  for (j=0; j<scaley; ++j) {
    glVertex3fv(v[i*scaley+j]);
    glVertex3fv(v[i*scaley+(j+1)%scaley]);
    glVertex3fv(v[(i+1)*scaley+(j+1)%scaley]);
    glVertex3fv(v[(i+1)*scaley+j]);
  }
}
glEnd();
}


void RenderScene() 
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity (); 

  glRotatef(fRotation,1,0,0);
  glColor3f(1,0,0);
  drawHalfSphere(25.0,25.0,0.5);
  glutSwapBuffers();
}

当我旋转Hemi Sphere时,有一个Point,球体的各个部分消失。 它就像一面墙,在我旋转球体后面。

1 个答案:

答案 0 :(得分:1)

您是否在初始化期间尝试过:

glCullFace(GL_FRONT_AND_BACK);

或者你的飞机太近了:

 void gluPerspective(...,GLdouble zFar);