OpenGL 画圆
// DrawBall.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<gl/glut.h> #include<stdlib.h> #include<math.h> #include<stdio.h> #include<iostream> using namespace std; //画圆的方法 void drawFilledCircle(float x0, float y0, float radius, int sections) { float alpha; glBegin(GL_TRIANGLE_FAN); glVertex2f(x0, y0); for (int count = 0; count <= sections; count++) { alpha = count * 2 * 3.1415926 / sections; glVertex2f(x0 + radius*cos(alpha), y0 + radius*sin(alpha)); cout << alpha << endl; } glEnd(); } void init(void)//初始化 { glClearColor(1.0, 1.0, 1.0, 0.0);//清屏色 glOrtho(-2.0, 2.0, -2.0, 2.0, 2.0, -2.0);//视见体 } void display(void)//重绘屏幕 { glClear(GL_COLOR_BUFFER_BIT);//清除颜色缓存 glColor3f(0.0, 0.0, 1.0);//当前颜色 drawFilledCircle(0.0, 0.0, 1.0,100);//在这里写绘制函数 //glutSwapBuffers();//动画显示 glFlush();//静态显示 赶紧显示 } int main(int argc, char** argv) { glutInit(&argc, argv);//glut库与控制台初始化函数 //glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);//显示模式 单双缓存 颜色模式 深度 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(500, 200);//窗口的位置 窗口左上角距离屏幕左上角 glutInitWindowSize(500, 500); glutCreateWindow(" BallMovement ");//窗口名字 init();//调用自定义的初始化函数 glutDisplayFunc(display);//注册显示回调函数 glutMainLoop();//进入事件循环 return 0; }
用割圆法
count个三角形面扇
alpha是圆心角的大小
作品原创 转载请注明出处