지난번에 만든 창의 크기를 조절하면 다음과 같이 된다.



다음과 같이 찌그러진다.


기본적으로 높이와 너비의 비율을 1:1로 그리기 때문에 찌그러지는거다.


안찌그러지게 창의 크기가 변하면 비율을 조정해줘야한다


void glutReshapeFunc (void (* func) (int 폭, int 높이));

이걸로 해야된다.


(이걸로 콜백을 등록하면 윈도우가 만들어질 때도 한번 불림)


그냥 이렇게 추가해줌


이제 Reshape이라는 함수를 만들어줘야함


void Reshape(int w, int h)

{

    if(h == 0)

        h = 1;

    

    float ratio = 1.0f * w/h;

    

    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    glViewport(0, 0, w, h);

    gluPerspective(45, ratio, 1, 100);

    glMatrixMode(GL_MODELVIEW);

}



이거임


h로 나눌 것이기 때문에 0일 경우를 막아주고


비율을 정한다.


* void glMatrixMode(GLenum mode);

- 렌더링 파이프라인에서 사용할 Matrix를 지정한다.

GL_MODELVIEW

Applies subsequent matrix operations to the modelview matrix stack.

GL_PROJECTION

Applies subsequent matrix operations to the projection matrix stack.

GL_TEXTURE

Applies subsequent matrix operations to the texture matrix stack.

GL_COLOR

Applies subsequent matrix operations to the color matrix stack.


위와 같은 네가지 모드를 선택할 수 있다.



void glLoadIdentity(void);
- 지정한 Matrix를 Identity Matrix(단위행렬)로 바꿈 

* void glViewPort(GLint x, GLint y, GLsizei w, GLsizeh h);

- 윈도우에서 어디에 그림을 얼마만큼 그릴지 정함


* void gluPerspective(GLdouble 화각, GLdouble 종횡비, GLsizei ClippingPlane 앞부분, GLsizeh ClippingPlane 뒷부분);

- view frustum의 좌표계를 설정한다


마지막에 glMatrixMode를 ModelView로 바꾸는건 보통 이걸 기본으로 사용하기 때문에 안전빵으로 해놓은 것



저렇게 쓰고 실행한 후 창의 크기를 바꾸면




'OpenGL' 카테고리의 다른 글

[OpenGL]GLUT Keyboard  (1) 2017.07.01
[OpenGL]GLUT Idle  (0) 2017.07.01
[OpenGL]GLUT Initializatio  (0) 2017.06.24
xcode에서 opengl 프로젝트 만들기  (0) 2017.06.23

+ Recent posts