When I create a new GLUT/openGL program the window sizing makes the top of the screen +1 and the bottom -1 in the x direction, I would like the coordinates to match the pixel size of the window. I want to do this because when I reshape my window the project is distorted. All I'm looking for is the name of the function I should read into.
2 Answers
This function is part of my project and it prevent distortion.
GLvoid myWidget::resizeGL(GLint width, GLint height) {
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, //The camera angle
(double)width / height,//The width-to-height ratio
1.0, //The near z clipping coordinate
100.0); //The far z clipping coordinate
glMatrixMode(GL_MODELVIEW);
}
Comments
From my project
void GLWidget::resizeGL(int width, int height)
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
w_screen=width; // GLWidget members (u don't need these)
h_screen=height; //
float ratio=width/height;
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov,ratio,0.1f,200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
fov in my case is a public member (initialized to 45)
Hope it helps