void CShape2D::drawCircle() {
static bool bDrawSemiCircle = false;
glClear(GL_LINE_BIT);
glBegin(GL_LINES);//可以改成GL_POINTS,具体含义参照gl文档
//方法1
//glPointSize(5.0f);//只对Begin的参数为GL_POINTS有用,glLineWidth:设置Line的宽度此时设置PointSize也是没有效果
//if(bDrawSemiCircle) {
// glColor3f(0.0f, 0.0f, 1.0f);
// if(beginPoint_.x > -radius_) {
// for(GLfloat fVaule = radius_; fVaule >= beginPoint_.x; fVaule -= 0.0001f) {
// glVertex2f(fVaule, -sqrt(radius_ * radius_ - fVaule * fVaule));
// }
// beginPoint_.x -= 0.01f;
// }
//} else {
// glColor3f(0.0f, 1.0f, 0.0f);
// if(beginPoint_.x > radius_) {
// beginPoint_.x = radius_;
// bDrawSemiCircle = true;
// } else {
// for(GLfloat fVaule = -radius_; fVaule <= beginPoint_.x; fVaule += 0.0001f) {
// glVertex2f(fVaule, sqrt(radius_ * radius_ - fVaule * fVaule));
// }
// beginPoint_.x += 0.01f;
// }
//}
//方法2
glColor3f(1.0f, 0.0f, 0.0f);
if(beginPoint_.x <= 2.0f * Pi) {
for(GLfloat fVaule = 0; fVaule <= beginPoint_.x; fVaule += 0.001f) {
glVertex2f(radius_ * cos(fVaule), radius_ * sin(fVaule));
}
beginPoint_.x += 0.02f;
}
glEnd();
glFlush();
glutSwapBuffers();
}
方法一还有一个bug就是首尾端点没连接到,自己接下来慢慢调试
OpenGL画圆
最新推荐文章于 2022-07-28 18:22:57 发布