首页 > 代码库 > OpenGL画圆

OpenGL画圆

OpenGL画圆代码,代码很简单。。。

截图如下:

#include<GL/glut.h>
#include<math.h>
#include<stdio.h>
GLint x=250;
GLint y=450;
void init()
{
    glClearColor(1.0,1.0,1.0,0.0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0,600,0,500);
}
void lineSegment()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1,0,0);
    glBegin(GL_LINES);
    for(double i=0;i<=360;i+=3)
    {
        glVertex2d(x,y);
        double d1=250+200*sin(i/180*3.14);
        double d2=250+200*cos(i/180*3.14);
        glVertex2d(d1,d2);
        x=d1;
        y=d2;
    }
    glEnd();
    glFlush();
}
void main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowPosition(50,50);
    glutInitWindowSize(600,500);
    glutCreateWindow("An example opengl Program");
    init();
    glutDisplayFunc(lineSegment);
    glutMainLoop();
}