무작위 선을 50~250개 그려보았다.
소스
결과
소스
1 #include <stdio.h>
2 #include <GL/glut.h>
3
4 void drawRandomLines(int num){
5 static GLfloat width = 2.0;
6 static GLfloat height = 2.0;
7 int i=0;
8 GLfloat x,y;
9 inline void drawLine(GLfloat x, GLfloat y){
10 glVertex2f(x,y);
11 }
12
13 glBegin(GL_LINES);
14 {
15 for(i=0; i<num; i++){
16 glVertex2f(0.0,0.0);
17 glColor3f(rand()%10/10.0, rand()%10/10.0, rand()%10/10.0);
18 x = (rand()%100)/50.0 - width/2.0;
19 y = (rand()%100)/50.0 - height/2.0;
20 drawLine(x,y);
21 }
22 }
23 glEnd();
24 }
25
26 void DoDisplay()
27 {
28 glClear(GL_COLOR_BUFFER_BIT);
29 drawRandomLines(250);
30 glFlush();
31 }
32
33 int main(int argc, char *argv[])
34 {
35 glutInit( &argc, argv );
36 glutCreateWindow("OpenGL");
37 glutDisplayFunc(DoDisplay);
38 glutMainLoop();
39 }
2 #include <GL/glut.h>
3
4 void drawRandomLines(int num){
5 static GLfloat width = 2.0;
6 static GLfloat height = 2.0;
7 int i=0;
8 GLfloat x,y;
9 inline void drawLine(GLfloat x, GLfloat y){
10 glVertex2f(x,y);
11 }
12
13 glBegin(GL_LINES);
14 {
15 for(i=0; i<num; i++){
16 glVertex2f(0.0,0.0);
17 glColor3f(rand()%10/10.0, rand()%10/10.0, rand()%10/10.0);
18 x = (rand()%100)/50.0 - width/2.0;
19 y = (rand()%100)/50.0 - height/2.0;
20 drawLine(x,y);
21 }
22 }
23 glEnd();
24 }
25
26 void DoDisplay()
27 {
28 glClear(GL_COLOR_BUFFER_BIT);
29 drawRandomLines(250);
30 glFlush();
31 }
32
33 int main(int argc, char *argv[])
34 {
35 glutInit( &argc, argv );
36 glutCreateWindow("OpenGL");
37 glutDisplayFunc(DoDisplay);
38 glutMainLoop();
39 }
결과
'OpenGL' 카테고리의 다른 글
#4. OpenGL koch snowflake (코흐 눈송이) (0) | 2011.08.03 |
---|---|
#2. OpenGL 두번째 예제. 사각형 그려보기 (0) | 2011.07.12 |
#1. OpenGL 설치 및 예제 파일 실행 (0) | 2011.07.12 |
Ubuntu에 OpenGL 설치하기 (0) | 2011.07.12 |