0

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.

1
  • on resize you need to adjust the aspect ratio by getting the new window size and hight, here a good example from another post stackoverflow.com/questions/3267243/… Commented May 27, 2013 at 16:48

2 Answers 2

0

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.