void CShape3D::drawCircle(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
//glTranslated(0.0f, 0.0f, 0.0f); //移动
glRotated(angle, 0.5f, 0.5f, 0.0f);// 旋转
angle += 1.0f;
glScaled(2.0f, 2.0f, 2.0f);//x, y, z放大2倍
scale += 0.1f;
static GLUquadricObj* qobj=gluNewQuadric( );
gluSphere(qobj,0.4,1000,10);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
//旋转正方形
void CShape::init() {
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB) ;
glutInitWindowSize(400, 400) ;
glutCreateWindow("I love OpenGl") ;
glutDisplayFunc(CShape::displayWindow) ;
glutSpecialUpFunc(CShape::getKey);
glutReshapeFunc(CShape::shapeFunc);
glutMainLoop() ;
}
void CShape::getKey(GLint iKey, GLint x, GLint y) {
switch (iKey)
{
case GLUT_KEY_UP:
g_sAngle += kAngleStep;
break;
case GLUT_KEY_DOWN:
g_sAngle -= kAngleStep;
break;
case GLUT_KEY_LEFT:
g_sAngle += kAngleStep;
break;
case GLUT_KEY_RIGHT:
g_sAngle -= kAngleStep;
break;
default:
break;
}
<span style="color:#ff0000;">glutPostRedisplay();//刷新一下屏幕,如果不添加这行代码,看到效果很困难</span>
}
void CShape::draw3DSprialLine() {
}
void CShape::displayWindow() {
glClear(GL_COLOR_BUFFER_BIT);
//glPushMatrix();
glRotated(g_sAngle, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES); // 绘制三角形
glVertex3f( 0.0f, 1.0f, 0.0f); // 上顶点
glVertex3f(-1.0f,-1.0f, 0.0f); // 左下
glVertex3f( 1.0f,-1.0f, 0.0f); // 右下
glEnd();
//glPopMatrix();
glutSwapBuffers();
}
void CShape::idleFunc() {
displayWindow();
}
void CShape::shapeFunc(GLint w, GLint h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 5.0f, 0.0f);
}