How to set a camera for glOrtho?

Hi,

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

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

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(left, right, top, bottom, near, far);
 
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
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 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?

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)
imageshack.com/a/img46/3267/lu5s.png

Here’s what I want to do:
imageshack.com/a/img853/2019/lb1v.png