#3. OpenGL 선 그려보기

OpenGL 2011. 7. 12. 18:56
무작위 선을 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 }

결과


Posted by Нуеоп
,