Reputation: 23
I recently started using LWJGL and noticed that the glOrtho
method takes the parameters left, right, bottom, top and cannot figure out what these correspond to.
I was confused when I noticed that
glOrtho(1, 1, 1, 1, 1, -1);
was the same as
glOrtho(-1, 1, -1, 1, 1, -1);
Am I correct in saying these to snippets of code are the same and if so why?
Upvotes: 2
Views: 998
Reputation: 6597
An orthographic projection is a rectangular parallelepiped (aka a box). The parameters for the glOrtho
call define the clipping planes, or edges, of this box. Anything that lies outside of the projection box will not be rendered.
In regards to your example calls, the first one (glOrtho(1,1,1,1,1,-1)
) is invalid and generates an GL_INVALID_OPERATION
). Why? An orthographic projection is defined as
Notice the division by 0 errors due to right == left
and top == bottom
.
The second example (glOrtho(-1,1,-1,1,1,-1)
) simply creates an identity matrix.
Chapter 3 - OpenGL Programming Guide - Projection Transforms
ScratchPixel - Orthographic Projection Tutorial
Upvotes: 4
Reputation: 45362
No, they are not the same:
glOrtho(1, 1, 1, 1, 1, -1);
will just generate a GL_INVALID_OPERATION
error, and the commend has no further effect. The error occurs when left==right or top==bottom or near==far. (If it did not check for that condition, a division by zero would occur).
glOrtho(-1, 1, -1, 1, 1, -1);
is effectively doing nothing, as it will multiply the current matrix by an identity matrix.
It might appear as if those commands have the same result, but what actually happens is quite different.
Upvotes: 4