Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: How to set a camera for glOrtho?

  1. #1
    Newbie Newbie
    Join Date
    Mar 2014
    Posts
    2

    Question 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

  2. #2
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    71
    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

    Code :
    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?
    Last edited by Brokenmind; 03-14-2014 at 12:55 PM.

  3. #3
    Newbie Newbie
    Join Date
    Mar 2014
    Posts
    2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •