PDA

View Full Version : glOrtho doesn't work



sernik
05-22-2015, 06:34 AM
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?

mhagain
05-22-2015, 10:30 AM
glOrtho ( Left , Left , 10.0 , 10.0 , .....
This is almost certainly not what you want; see https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml

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

sernik
05-22-2015, 02:03 PM
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 :)

Thread to close

nagesh
05-24-2015, 09:54 PM
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

mhagain
05-25-2015, 02:06 AM
Actually if you look at the documentatio for it: https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml 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.