填充多边形:调整    glBegin(GL_POLYGON);

#include <windows.h>

#include <gl/gl.h>

#include <gl/glu.h>

#include <gl/glut.h>

//

void myInit()

{

  glClearColor(1.0,1.0,1.0,0.0);

  glMatrixMode(GL_PROJECTION);

  glLoadIdentity();

  gluOrtho2D(0.0,640,0.0,480);

}

/

void myDisplay()

{

  glClear(GL_COLOR_BUFFER_BIT);

  glColor3f(1.0f, 0.f, 0.f);

  glEnable(GL_LINE_SMOOTH);

  glEnable(GL_BLEND);

  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

    glBegin(GL_POLYGON);

      glVertex2d(200, 20);

      glVertex2d(100, 300);

      glVertex2d(400, 500);

      glVertex2d(300, 70);

    glEnd();

  glFlush();

}

///

void main(int argc,char **argv)

{

  glutInit(&argc,argv);

  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

  glutInitWindowSize(640,480);

  glutInitWindowPosition(100,150);

  glutCreateWindow("my second attempt");

  glutDisplayFunc(myDisplay);

  myInit();

  glutMainLoop();

}

渲染空心多边形:调整    glBegin(GL_LINE_LOOP);

#include <windows.h>

#include <gl/gl.h>

#include <gl/glu.h>

#include <gl/glut.h>

//

void myInit()

{

  glClearColor(1.0,1.0,1.0,0.0);

  glMatrixMode(GL_PROJECTION);

  glLoadIdentity();

  gluOrtho2D(0.0,640,0.0,480);

}

/

void myDisplay()

{

  glClear(GL_COLOR_BUFFER_BIT);

  glColor3f(1.0f, 0.f, 0.f);

  glEnable(GL_LINE_SMOOTH);

  glEnable(GL_BLEND);

  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

  glLineWidth(10);

    glBegin(GL_LINE_LOOP);

      glVertex2d(200, 20);

      glVertex2d(100, 300);

      glVertex2d(400, 500);

      glVertex2d(300, 70);

    glEnd();

  glFlush();

}

///

void main(int argc,char **argv)

{

  glutInit(&argc,argv);

  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

  glutInitWindowSize(640,480);

  glutInitWindowPosition(100,150);

  glutCreateWindow("my second attempt");

  glutDisplayFunc(myDisplay);

  myInit();

  glutMainLoop();

}