[OpenGL] 간단한 큐브(Cube) 그리기 예제

Programming/OpenGL 2009/05/02 20:07

  
 glPushMatrix();
    glBegin(GL_QUADS);
 
       glVertex3f(0.0f, 0.0f, 0.0f); // top face
       glVertex3f(0.0f, 0.0f, -1.0f);
       glVertex3f(-1.0f, 0.0f, -1.0f);
       glVertex3f(-1.0f, 0.0f, 0.0f);

       glVertex3f(0.0f, 0.0f, 0.0f); // front face
       glVertex3f(-1.0f, 0.0f, 0.0f);
       glVertex3f(-1.0f, -1.0f, 0.0f);
       glVertex3f(0.0f, -1.0f, 0.0f);

       glVertex3f(0.0f, 0.0f, 0.0f); // right face
       glVertex3f(0.0f, -1.0f, 0.0f);
       glVertex3f(0.0f, -1.0f, -1.0f);
       glVertex3f(0.0f, 0.0f, -1.0f);

       glVertex3f(-1.0f, 0.0f, 0.0f); // left face
       glVertex3f(-1.0f, 0.0f, -1.0f);
       glVertex3f(-1.0f, -1.0f, -1.0f);
       glVertex3f(-1.0f, -1.0f, 0.0f);

       glVertex3f(0.0f, -1.0f, 0.0f); // bottom face
       glVertex3f(0.0f, -1.0f, -1.0f);
       glVertex3f(-1.0f, -1.0f, -1.0f);
       glVertex3f(-1.0f, -1.0f, 0.0f);

       glVertex3f(0.0f, 0.0f, -1.0f); // back face
       glVertex3f(-1.0f, 0.0f, -1.0f);
       glVertex3f(-1.0f, -1.0f, -1.0f);
       glVertex3f(0.0f, -1.0f, -1.0f);

    glEnd();
 glPopMatrix();

하나의 Quad마다 각 4개의 vertex를 CCW의 순서로 정해주는것이 뽀인트 이다.

저작자 표시
1 ... 31 32 33 34 35 36 37 38 39 ... 43


티스토리 툴바