Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

codingfarm

opengl 설치 및 예제, 컴파일 본문

computer graphics/opengl

opengl 설치 및 예제, 컴파일

scarecrow1992 2019. 12. 16. 17:54

아래 명령어로 opengl을 설치한다

 

sudo apt-get install -y build-essential
sudo apt-get install freeglut3-dev libglu1-mesa-dev mesa-common-dev

 

위 명령어 이후 /usr/include/GL 가 생긴것을 확인 가능하다

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "GL/freeglut.h" 
 
void init();
void display();
void drawPoints();
void keyboard(unsigned char key, int x, int y);
 
void drawPoints(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.01.01.0);
    glBegin(GL_POLYGON);
    glVertex2f(-0.50.0);
    glVertex2f(0.50.0);
    glVertex2f(0.01.0);
    glEnd();
    glFlush();
}
 
void keyboard(unsigned char key, int x, int y){
    switch(key){
        case 'q':
        case 'Q':
            exit(EXIT_SUCCESS);
            break;
        case 'r' :
        case 'R' :
            glClearColor(1.00.00.01.0);
            break;
    }
    glutPostRedisplay();
 
}
 
int main(int argc, char **argv) {
    int mode = GLUT_RGB | GLUT_SINGLE;
        
    // GLUT_RGB : True Color Mode
    // GLUT_DOUBLE : Use Double Buffer
    // Default Mode : GLUT_RGB | GLUT_SINGLE
 
    // Init GLUT & create Window
    glutInit(&argc, argv);
    glutInitDisplayMode(mode);    // Set drawing surface property
    glutInitWindowPosition(100100);    // Set window Position at Screen
    glutInitWindowSize(400,400);    // Set window size. Set printed working area size. Bigger than this size
    glutCreateWindow("OpenGL");    // Generate window. argument is window's name
    glutSetWindowTitle("exam");
    
    // Register Callback function before set glutMainLoop()
    glutDisplayFunc(drawPoints);
    glutKeyboardFunc(keyboard);
    glutMainLoop();    // Monitor message queue and Run the corresponding callback function
    return 1;
}
cs

 

컴파일을 한다

 

 

gcc exam.c -lglut -lGL -lGLU

 

실행해본다

./a.out

 

 

'computer graphics > opengl' 카테고리의 다른 글

기본 예제 분석  (0) 2020.03.21
설치 및 셋팅  (0) 2020.03.20
OpenGL 기초  (0) 2020.03.18
Comments