#include 
#include 
#include 
#include 
void display()
{
    GLfloat vertices[3][3] = {{0.0,0.0,0.0},
                              {25.0,50.0,0.0},
                              {50.0,0.0,0.0}};
    GLfloat p[3] = {7.5,5.0,0.0};
    int j, k;
    glBegin(GL_POINTS);
    for(k=0;k<5000;k++){
        j=rand()%3;
        p[0] = (p[0] + vertices[j][0])/2;
        p[1] = (p[1] + vertices[j][1])/2;
        glVertex3fv(p);
    }
    glEnd();
    glFlush();
}
void myinit()
{
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glColor3f(1.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 50.0, 0.0, 50.0);
    glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char *argv[])
{
    //QApplication a(argc, argv);
    //Widget w;
    //w.show();
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(0,0);
    glutCreateWindow("zzh");
    glutDisplayFunc(display);
    myinit();
    glutMainLoop();
    //return a.exec();
}

《交互式计算机图形学-OpenGL自顶向下》根据这本书,学习。以上代码,都来自此书。

使用qtCreator windows环境