-1

我想尝试创建一个半球体。

这是我的代码

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();
}

当我旋转半球时,有一个点,球的各个部分消失了。它就像一堵墙,在我旋转球体的后面。

4

1 回答 1

1

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

glCullFace(GL_FRONT_AND_BACK);

或者你的远方飞机太近了:

 void gluPerspective(...,GLdouble zFar);
于 2012-04-22T20:06:11.853 回答