소스
/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
실행 화면
'OpenGL' 카테고리의 다른 글
#4. OpenGL koch snowflake (코흐 눈송이) (0) | 2011.08.03 |
---|---|
#3. OpenGL 선 그려보기 (0) | 2011.07.12 |
#1. OpenGL 설치 및 예제 파일 실행 (0) | 2011.07.12 |
Ubuntu에 OpenGL 설치하기 (0) | 2011.07.12 |