Здравствуйте, у меня есть программа opengl, которая отображает двухмерные полигоны в ортогональной проекции. В начале программы или при изменении размера окна вызывается функция reshape. Вот код функции изменения формы:
/* Call back when the windows is re-sized */
void reshape(GLsizei width, GLsizei height) {
// Compute aspect ratio of the new window
if (height == 0) height = 1;
// To prevent divide by 0
GLfloat aspect = (GLfloat)width /
(GLfloat)height;
// Set the viewport to cover the new window
glViewport(0, 0, width, height);
// Set the aspect ratio of the clipping area to match the viewport
glMatrixMode(GL_PROJECTION); // To operate on the Projection matrix
glLoadIdentity(); // Reset the projection matrix
if (width >= height) {
clipAreaXLeft = -1.0 * aspect;
clipAreaXRight = 1.0 * aspect;
clipAreaYBottom = -1.0;
clipAreaYTop = 1.0;
}
else {
clipAreaXLeft = -1.0;
clipAreaXRight = 1.0;
clipAreaYBottom = -1.0 / aspect;
clipAreaYTop = 1.0 / aspect;
}
clipAreaXLeft *= 600;
clipAreaYBottom *= 600;
clipAreaXRight *= 600;
clipAreaYTop *= 600;
gluOrtho2D(clipAreaXLeft, clipAreaXRight,
clipAreaYBottom, clipAreaYTop);
glScissor(0, 0, width, height);
glEnable(GL_SCISSOR_TEST);
}
Вот код для фрагментного шейдера GLSL:
#version 420 core
out vec4 color
void main(){
vec2 orthoXY =... need help here, should
convert window-space to ortho-space,
maybe use projection matrix from fixed
pipeline?
color=vec4{1,1,1,1}
}