//#define GLUT_DISBALE_ATEXIT_HACK
#define GLUT_DISABLE_ATEXIT_HACK
#include
#include
#include
//#include
#include
#define PI 3.1415926
//清除窗口初始化
void init()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_FLAT);
}
/*改变大小*/
void ChangeSize(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
gluPerspective(60, 1, 0.1, 100); // 设置投影转换
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, -2, 0, 0, 0, 0, 1, 0); // 设置视点
}
GLfloat R = 0.5f;
//绘制物体
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
//画坐标轴
glBegin(GL_LINES);
glVertex2f(-1.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(0.0f, 1.0f);
glVertex2f(0.0f, -1.0f);
glEnd();
//画圆....
glBegin(GL_LINE_LOOP);
for (int i = 0; i <= 1000; ++i)
{
glVertex2f(R*cos(2 * PI / 1000 * i), R*sin(2 * PI / 1000 * i));
}
glEnd();
glFlush();
}
//定义窗口
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(200, 200);
glutInitWindowSize(300, 300);
glutCreateWindow("draw circle");
init();
//glutDisplayFunc(display);
glutReshapeFunc(ChangeSize);
glutDisplayFunc(display);
glutIdleFunc(display);
//glutIdleFunc();
glutMainLoop();
return 0;
}