ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [OpenGL] 예제1_화면에 도형 띄우기
    Programming Language/OpenGL 2017. 4. 10. 13:47
    반응형

    glClearColor,

    glClear,

    glBegin,

    glEnd,

    glFinish,

    glutDisplayFunc,

    glutMainLoop


    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
    #include <iostream>
    #include <gl/glut.h>
     
    void display(){
        glClearColor(1.f, 1.f, 1.f, 1.f);//specify R,G,B,A values used when the color buffers are cleared. The initial values are all 0.
        glClear(GL_COLOR_BUFFER_BIT);//clear buffers to preset values.
        glColor3f(0.f, 0.f, 1.f);
        glBegin(GL_POLYGON);//glBegin and glEnd delimit the vertices that define a primitive or a group of like primitives. glBegin accepts a single argument that specifies in which of then ways the vertices are interpreted.(점들이 어느 도형으로 해석되어야 하는가)
            glVertex2f(-0.5-0.5f);
            glVertex2f(0.5-0.5f);
            glVertex2f(0.50.5f);
            glVertex2f(-0.50.5f);
        glEnd();
        glFinish();//block until all GL execution is complete. glFinish does not return until the effects of all previously called GL commands are complete.
        //c.f. glFlush : flFlush can return at any time. It does not wait until the execution of all previously issued GL commands is complete. glFlush empties buffers, cuausing all issued commands to be executed as quickly as they are accepted by the actual rendering engine.
        //glFlush가 리턴한 후, 유한한 시간 안에 모든 GL 명령어들이 끝나는 것을 보증한다. glFinish는 리턴하기 전에 모든 명령어들이 실행된다는 것을 보증한다.
        //glFlush는 명령을 보내기만 함. glFinish는 명령이 다 처리될 때까지 기다림.
        //glFinish보다 glFlush를 하면 속도가 좀 더 빨라지는 것 같다.
    }
     
    int main(int argc, char** argv){
        glutInit(&argc, argv);
        glutCreateWindow("exex");
        glutDisplayFunc(display);//glutDisplayFunc sets the display callback for the current window. display함수를 호출한다.
        glutMainLoop();//glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.
     
        return EXIT_SUCCESS;//EXIT_SUCCESS == 0.  it is the same as return 0;
    }
     
    /*
    callback : 다른 코드의 인수로서 넘겨주는 실행 가능한 코드.
    references
    https://www.opengl.org/resources/libraries/glut/spec3/node46.html
    https://ko.wikipedia.org/wiki/%EC%BD%9C%EB%B0%B1
    https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glBegin.xml
    http://www.gpgstudy.com/forum/viewtopic.php?p=43524
    */
     
     
    cs


    반응형

    'Programming Language > OpenGL' 카테고리의 다른 글

    [OpenGL] Rasterization  (0) 2017.04.11
    [OpenGL] 예제2_정육면체 그리기  (0) 2017.04.11
    [Visual Studio] OpenGL 프로젝트 생성하기  (0) 2017.04.10
    [OpenGL] glFrustum  (0) 2017.03.28
    [OpenGL] gluUnProject  (0) 2017.03.28
Designed by Tistory.