View Full Version : How to set a camera for glOrtho?

03-14-2014, 12:28 PM

I know technically openGL does not have a camera. I am a total beginner, but if I understand correctly, I cam move the "camera" or my "eye" with function gluLookAt. But: gluLookAt looks at a scene from one specific point (it uses a perspective). Since I am using glOrtho, I do not have a specific point from where to look at. I project a scene to a square, so all I need to define my "camera" is not a one-point "eye" but a square in space, and a direction from which I need to project the scene to that square. So if I have a direction defined with a vector, and I have a square to which I want to project - how do I do that?

Best regards

03-14-2014, 12:39 PM
In openGL, the projection will be performed either with perspective or with parallel projection, which internally are glFrustum or glOrtho. But still, in order to tell openGL how you want to look at this scene, even before projecting it, you need a gluLookAt. I think you want to also display objects behind the imaginary camera, but I don't think that's possible. In your case you would need to use

glOrtho(left, right, top, bottom, near, far);

glLookAt(eye.x, eye.y, eye.z, eye.x+direction.x, eye.y+direction.y, eye.z+direction.z, up.x, up.y, up.z);

You would need to choose reasonable values for the eye coordinate, as you most likely cannot use glOrtho with negative near values. This (https://www.opengl.org/discussion_boards/showthread.php/130569-negative-znear-or-zfar-values-in-glOrtho) thread discusses this:

The screen is always at z=0. So if you set zNear less than 0 (which gluOrtho2D does by the way), then it puts that plane behind the viewpoint.

But what do you want to achieve by doing this anyway?

03-15-2014, 01:17 AM
Here's a quick sketch of what I want to achieve. I have a rectangle defined with X1, X2, X3 and X4 - and a vector of direction in which I want to view. I only want to view in that direction, not interested in what's behind a "camera". The only problem here is I do not have a "camera" but rather a "screen" or "canvas" on which I want to project.

Here's what's a normal projection with glOrtho looks like:
(The forum doesn't want to post my images, so I'm hoping I'm not violating any forum policies, but here is the link to the image)

Here's what I want to do: