- #include <GL/glut.h>
- #include <stdlib.h>
- #include <stdio.h>
- #define NUMOFPOINTS 50000
- struct Point
- {
- float x;
- float y;
- } a[NUMOFPOINTS + 1];
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- srand((unsigned)time(NULL));
- int i;
- int j;
- for(i = 0; i <= NUMOFPOINTS; i++)
- {
- if(rand()%2 == 1)
- j = 1;
- else
- j = -1;
- a[i].x = j*(float)rand()/RAND_MAX;
- if(rand()%2 == 1)
- j = 1;
- else
- j = -1;
- a[i].y = j*(float)rand()/RAND_MAX;
- }
- struct Point *p;
- p = a;
- glBegin(GL_POINTS);
- for(i = 0; i <= NUMOFPOINTS; i++)
- {
- glVertex2f((p+i)->x,(p+i)->y);
- }
- glEnd();
- glFlush();
- }
- int main(int argc, char *argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(400, 400);
- glutCreateWindow("Points");
- glutDisplayFunc(display);
- glutMainLoop();
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1708201513472.html
来源: http://www.codesnippet.cn/detail/1708201513472.html