glOrtho doesn't work

Hi guys!
In my code, I’m using glOrtho and it doesn’t make result. If I compile without glOrtho, it’s the same.

This is my code:


void GLWidget::initializeGL()
{
    glClearColor(1,0,1,1);
}

void GLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glLoadIdentity();

    glBegin ( GL_QUADS );
        glColor3f(1,0,0);
        glVertex2f ( 0.0 , 0.0 );
        glVertex2f ( 0.5 , 0.0 );
        glVertex2f ( 0.5 , 0.5 );
        glVertex2f ( 0.0 , 0.5 );
    glEnd();
}

void GLWidget::resizeGL(int width,int height)
{
    glViewport(0,0,width,height);
    const register double Left = (double)width*10/(double)height;
    glMatrixMode ( GL_PROJECTION );
    glLoadIdentity();
    glOrtho ( Left , Left , 10.0 , 10.0 , -1.0 , 1.0 );
    glMatrixMode ( GL_MODELVIEW );
    glLoadIdentity();
}

Does anybody know why it doesn’t work?

glOrtho ( Left , Left , 10.0 , 10.0 , ..... 

This is almost certainly not what you want; see glOrtho

GL_INVALID_VALUE is generated if left = right, or bottom = top, or near = far.

Thanks

My new Line with glOrtho

glOrtho ( -Left , Left , 10.0 , -10.0 , -1.0 , 1.0 );

2 chars less and code doesn’t work :slight_smile:

Thread to close

Hi,

I guess in opengl for ortho if (left==right) or (top == bottom) or (far == near) it will raise a invalid value error. if u quiry glGetError() u will get it. So i guess you r using ortho fun wrongly…

Try with this “glOrtho ( 10.0 , Left , 10.0 ,Left , -1.0 , 1.0 );”

Now it may work

Regards,
Nagesh

Actually if you look at the documentatio for it: glOrtho you’ll see that the generated matrix uses division by “right - left”, “top - bottom” and “far - near” in a number of places.

If these values were equal it would be division by zero.