소프트웨어/openGL

openGL | openGL 2강-화면(2)

개발자_이훈규 2014. 1. 10. 17:30


    환경 : ubuntu 13.10 64bit


http://yooninsung.blog.me/30090383243

위 블로그의 코드를 수정하였습니다.

위 블로그는 window 운영체제, 저는 우분투 운영체제에서 코드를 수정해서 동작했습니다.

(Ubuntu 13.10)



기존의 소스를 그대로 사용

$ cp lecture2.cpp lecture3.cpp


컴파일

g++ lecture3.cpp -lGL -lGLU -lglut -o lecture3


소스

#include <GL/freeglut.h>

#include <GL/gl.h>


void cosmosDisplay() {

    glClear(GL_COLOR_BUFFER_BIT);

    glutSolidTeapot(0.5);

    glFlush();

}


int main(int argc, char** argv) {

    glutInit(&argc, argv);

    glutInitWindowSize(800, 600);

    glutCreateWindow("Dev Kyu openGL chapter1 from RintlanTta");

    glutDisplayFunc(cosmosDisplay);


    glutMainLoop();


    return 0;

}



화면





---------------------------------

소스

#include <GL/freeglut.h>

#include <GL/gl.h>


void cosmosDisplay() {


    glViewport(0, 0, 800, 600);

    glClear(GL_COLOR_BUFFER_BIT);


    glutSolidTeapot(0.5);

    glFlush();

}


int main(int argc, char** argv) {

    glutInit(&argc, argv);

    glutInitWindowSize(800, 600);

    glutCreateWindow("Dev Kyu openGL from RintlanTta");

    glutDisplayFunc(cosmosDisplay);


    glutMainLoop();


    return 0;

}


화면



-------------------


그대로 따라했는데 주전자가 바로 사라진다. 그래서 glOrtho함수를 공부한다.


http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml



C Specification

void glOrtho(GLdouble  left,
 GLdouble  right,
 GLdouble  bottom,
 GLdouble  top,
 GLdouble  nearVal,
 GLdouble  farVal);



glOtrho의 개념이 바뀌었다(?) 보니깐 배율로 작성된다.

http://minimonk.tistory.com/2893


댓글에 카메라 기능을 공부하면 이 현상이 이해가 된다고 하여 일단 PASS


원본 소스

#include <GL/freeglut.h>

#include <GL/gl.h>


void cosmosDisplay() {


    glViewport(0, 0, 800, 600);

    glClear(GL_COLOR_BUFFER_BIT);

    glOrtho(-400, 400, -300, 300, -250, 250);


    glutSolidTeapot(200);

    glFlush();

}


int main(int argc, char** argv) {

    glutInit(&argc, argv);

    glutInitWindowSize(800, 600);

    glutCreateWindow("Dev Kyu openGL from RintlanTta");

    glutDisplayFunc(cosmosDisplay);


    glutMainLoop();


    return 0;

}


수정 소스
#include <GL/freeglut.h>
#include <GL/gl.h>



void cosmosDisplay() {

    glViewport(0, 0, 800, 600);
    glClear(GL_COLOR_BUFFER_BIT);
//    glOrtho(-400, 400, -300, 300, -100, 100);
    glOrtho(-1, 1, -1, 1, -1, 1);

    glutSolidTeapot(0.5);
    glFlush();
}

int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitWindowSize(800, 600);
    glutCreateWindow("Dev Kyu openGL from RintlanTta");
    glutDisplayFunc(cosmosDisplay);

    glutMainLoop();

    return 0;
}

수정 소스 - 화면



수정 소스 - 2

#include <GL/freeglut.h>

#include <GL/gl.h>




void cosmosDisplay() {


    glViewport(0, 0, 800, 600);

    glClear(GL_COLOR_BUFFER_BIT);

//    glOrtho(-400, 400, -300, 300, -100, 100);

    glOrtho(-1, 1, -1, 1, -0.5, 0.5);


    glutSolidTeapot(0.5);

    glFlush();

}


int main(int argc, char** argv) {

    glutInit(&argc, argv);

    glutInitWindowSize(800, 600);

    glutCreateWindow("Dev Kyu openGL from RintlanTta");

    glutDisplayFunc(cosmosDisplay);


    glutMainLoop();


    return 0;

}


수정 소스 - 2 - 화면



결론 - 비율이다.