Search code examples
openglopengl-esopengl-3

OPEN GL(glOrtho functiion)


what is the exact meaning of this function

if(w<=h)
glortho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-2.0,2.0);
else
glortho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-2.0,2.0,-2.0,2.0);

I know that glortho is used for orthographic view that is 3d objects can be viewed that is (left,right,bottom,top near,far)views

why is negative and positive signs are used and why it divided by height and width


Solution

  • As you know, the glOrtho call takes as its parameters the left, right, top, and bottom values for the first 4 parameters. What this is doing is adjusting the aspect ratio of the projection based on the width and height of something (probably the window or viewport being drawn into). If the width is less than the height, then it will scale the height by the ratio of height to width and leave the width at 4 units (-2 to +2). If the height is less than the width, then it leaves the height at 4 units, and scales the width to maintain the correct aspect ratio.