点与线段

画点、线、折线段、闭合折线段

另外,可以通过以下方法来进行debug

#include<Windows.h>
#include<GL/glut.h>
#include<cstdio>
#include<cmath>

int point[] = { 100, 100 };
const double PI = acos(-1.0);

void displayVertex()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3d(0.5, 0.5, 0.5);
    glBegin(GL_POINTS);//用整数对给出坐标
    {
        glVertex2i(50, 100);
        glVertex2i(75, 150);
        glVertex2i(100, 200);
    }
    glEnd();
    glBegin(GL_POINTS);//用向量的形式给出坐标
    {
        glVertex3iv(point);
    }
    glEnd();
    glFlush();
}

void displayLine()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3d(0.5, 0.5, 0.5);
    glBegin(GL_LINES);//线段以点对形式给出,最后一个奇数点不被处理
    {
        glVertex2i(150, 150);
        glVertex2i(200, 150);
        glVertex2i(175, 100);
        glVertex2i(175, 200);
        glVertex2i(200, 200);
    }
    glEnd();
    glBegin(GL_LINE_STRIP);//折线形式给出
    {
        glVertex2i(300, 100);
        glVertex2i(300, 300);
        glVertex2i(500, 100);
        glVertex2i(500, 300);
    }
    glEnd();
    glBegin(GL_LINE_LOOP);//封闭折线
    {
        glVertex2i(600, 100);
        glVertex2i(600, 200);
        glVertex2i(700, 100);
    }
    glEnd();
    int centerx = 400, centery = 400;
    double radius = 100;
    glBegin(GL_LINE_LOOP);
    {
        for (int i = 0; i < 360; ++i)
        {
            double theta = PI * i / 180.0;
            glVertex2d(centerx + radius * cos(theta),
                centery + radius * sin(theta));
        }
    }
    glEnd();

    GLenum code = glGetError();
    if (code != GL_NO_ERROR)
    {
        fprintf(stderr, "error: %s\n", gluErrorString(code));
    }
    glFlush();
}


int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(800, 600);
    glutCreateWindow("Test the vertex and line");
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0.0, 800.0, 0.0, 600.0);
    glutDisplayFunc(displayLine);
    glutMainLoop();
}