OpenGL
#2. OpenGL 두번째 예제. 사각형 그려보기
Нуеоп
2011. 7. 12. 18:33
소스
/home/hyeon/programming/opengl/sample4.c.html
컴파일
실행 화면
1 #include <GL/glut.h>
2
3 void drawRectangle(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b)
4 {
5 static GLfloat width = 1.0;
6 static GLfloat height = 1.0;
7
8 glBegin(GL_POLYGON);
9 {
10 glColor3f(r,g,b);
11 glVertex2f(x,y);
12 glColor3f(r,b,g);
13 glVertex2f(x+width,y);
14 glColor3f(g,r,b);
15 glVertex2f(x+width,y+height);
16 glColor3f(b,g,r);
17 glVertex2f(x,y+height);
18 }
19 glEnd();
20 }
21
22 void DoDisplay()
23 {
24 glClear(GL_COLOR_BUFFER_BIT);
25 drawRectangle(-0.5,-0.5, 0.8,0.2,0.1);
26 glFlush();
27 }
28
29 int main(int argc, char *argv[])
30 {
31 glutInit( &argc, argv );
32 glutCreateWindow("OpenGL");
33 glutDisplayFunc(DoDisplay);
34 glutMainLoop();
35 }
2
3 void drawRectangle(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b)
4 {
5 static GLfloat width = 1.0;
6 static GLfloat height = 1.0;
7
8 glBegin(GL_POLYGON);
9 {
10 glColor3f(r,g,b);
11 glVertex2f(x,y);
12 glColor3f(r,b,g);
13 glVertex2f(x+width,y);
14 glColor3f(g,r,b);
15 glVertex2f(x+width,y+height);
16 glColor3f(b,g,r);
17 glVertex2f(x,y+height);
18 }
19 glEnd();
20 }
21
22 void DoDisplay()
23 {
24 glClear(GL_COLOR_BUFFER_BIT);
25 drawRectangle(-0.5,-0.5, 0.8,0.2,0.1);
26 glFlush();
27 }
28
29 int main(int argc, char *argv[])
30 {
31 glutInit( &argc, argv );
32 glutCreateWindow("OpenGL");
33 glutDisplayFunc(DoDisplay);
34 glutMainLoop();
35 }
컴파일
$ gcc -o sample4 sample4.c -lglut
실행 화면