glOrtho 와 glViewprt 는 화면에 그리고자 하는 Shape을 원하던 위치와 원하던 사이즈로 표현가능하도록 도와줍니다.

glViewport 는 윈도우상에 표현하고자 하는 사물이 그려지는 영역(area)를 정의합니다. 예를들어 사물이 표시되는 영역을 전체 영역으로 설정하는것은 아래와 같습니다.

glViewport(0, 0, ClientWidth, ClientHeight);
// 처음 두개의 매개변수는 좌측 하단 좌표, 나머지는 사이즈 정보값.

위와같이 설정하면 아래 그림처럼 윈도우 전체 영역에 걸쳐 사물이 그려집니다.


만약 윈도우 창의 좌하단 25픽셀 영역에서만 사물을 그려지게 하고 싶다면 아래와 같이 설정합니다.

glViewport(0, 0, 25, 25);

만약 처음 두개의 매개변수를 마이너스로 설정하면, 그려지는 영역은 화면 좌측으로 영역을 벗어나게 됩니다.

void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
procedure glViewport(x,y: GLint; width, height: GLsizei); stdcall;
x, y Specify the lower left corner of the viewport rectangle, in pixels. The default is (0, 0).
width, height Specify the width and height, respectively, of the viewport. When a GL context is first attached to a window, width and height are set to the dimensions of that window.

glOrtho

void glOrtho(GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble near,
GLdouble far)

procedure glOrtho (left, right, bottom, top, zNear, zFar: GLdouble); stdcall;
left, right Specify the coordinates for the left and right vertical clipping planes.
bottom, top Specify the coordinates for the bottom and top horizontal clipping planes.
near, far Specify the distances to the nearer and farther depth clipping planes. These distances are negative if the plane is to be behind the viewer.

glOrtho 는 glViewport 와 관련있지만 개념은 완전히 다릅니다. OpenGL에서는 기존의 윈도우 좌표체계를 완전히 무시할수 있습니다. 즉, glOrtho를 설정함으로써 자신이 원하는 좌표체계를 만들수 있습니다.

작업중인 윈도우 사이즈가 640X480 이라고 가정합니다. 하지만 당신은 이 윈도우 사이즈를 1 X 1로 설정할수 있습니다. 즉 1X1로 설정한 위도우에서 0.5X0.5 는 실제 윈도우 창의 320X240 좌표가 됩니다.
Posted by 웹눈