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 7 of 7

Thread: how do we get GL_VIEWPORT_MATRIX

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Hyderabad, AP, IN
    Posts
    11

    how do we get GL_VIEWPORT_MATRIX

    Hi,
    I am doing Image Based Rendering and want the camera calibration. We chose OpenGL, but getting the final Camera Matrix in the form

    [x y z] = K[R |t] [X Y Z]'

    has become difficult.

    {Assuming a simple pin-hole camera model,
    K is a 3x3 camera internal parameter matrix. R,t are Rotation Translation values}


    As in GL gives GL_MODELVIEW_MATRIX
    and GL_PROJECTION_MATRIX only
    but now a matrix form viewport tranformation.

    [ w/2 0 w/2 ]
    [ 0 h/2 h/2 ]
    [ 0 0 0 ]

    The above matrix did not give the same
    points.

    please let me know how to get this viewport transform in a matrix form.

    [screen_pt] = [vpt] [projective_tran] [modelview_tran] [world_point]
    ^^^^

    regards
    --
    Santhosh
    santhosh@gdit.iiit.net
    regards
    --
    Santhosh
    santhosh@gdit.iiit.net

  2. #2
    Senior Member OpenGL Pro cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    1,058

    Re: how do we get GL_VIEWPORT_MATRIX

    Pixels are sampled at the pixel center.

    If you want to pretend they're sampled at
    the pixel corner, you'll need to add an extra (.5, .5) bias to your projection matrix...
    Cass Everitt -- cass@xyzw.us

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Hyderabad, AP, IN
    Posts
    11

    Re: how do we get GL_VIEWPORT_MATRIX

    Can I get a viewport transformation matrix
    that will complete the set of matrices
    involved in a 3D->2D mapping
    regards
    --
    Santhosh
    santhosh@gdit.iiit.net

  4. #4
    Senior Member OpenGL Pro cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    1,058

    Re: how do we get GL_VIEWPORT_MATRIX

    I don't understand the question.

    The mapping from object space to window space is well defined. You just need to specify the appropriate matrices to use input coordinates of your choice.

    What *exactly* are you trying to do?

    Cass
    Cass Everitt -- cass@xyzw.us

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Hyderabad, AP, IN
    Posts
    11

    Re: how do we get GL_VIEWPORT_MATRIX

    I wanted the [vpt] transform mentioned in the first post
    yes, all the matrices are well defined like
    GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX
    but GL - does not maintain a GL_VIEWPORT_MATRIX which I am looking for
    This is because I wanted all transforms in matrix form only
    regards
    --
    Santhosh
    santhosh@gdit.iiit.net

  6. #6
    Member Regular Contributor
    Join Date
    Jun 2002
    Posts
    371

    Re: how do we get GL_VIEWPORT_MATRIX

    gl doesn't store any GL_VIEWPORT_MATRIX matrix, you have to get the viewport using glGet(GL_VIEWPORT). I guess this is because the viewport transform is a simple affine transform.

    "[screen_pt] = [vpt] [projective_tran] [modelview_tran] [world_point]"

    You don't say what kind of projection you are using. If perspective this is not possible because, well its perspective, you divide with your depth coordinate before the viewport transform.

    "The above matrix did not give the same points."

    The viewport transformation includes translation, you need to use homogeneous coordinates.

    A viewport matrix could be created like below in homogeneous coords, where
    x and y are bottom left window coordinates.

    w/2 0 0 (x + w/2)
    0 h/2 0 (y + h/2)
    0 0 1 0
    0 0 0 1

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Hyderabad, AP, IN
    Posts
    11

    Re: how do we get GL_VIEWPORT_MATRIX

    Thanks
    This worked
    [vpt] as

    | w/2___0___0_w/2 |
    | __0_h/2___0_h/2 |
    | __0___0___1___0 |
    | __0___0___0___1 |

    yes, my projection matrix represents perspective projection and the 3D is point need to be represented as [ X Y Z 1 ]' in this case.

    so that
    I get
    [x y z w]' = [vpt][perspective][modelview][X Y Z 1]'

    Then GL converts to 2D point as
    [x/w y/w z/w] and z/w is discretized to the depth buffer

    Unfortunately this image based rendering arithmetic doesnot assume a homogenous coord. system.

    But can the above situation can be approximated as a simple pin-hole perspective camera model with

    [x y z] = K(3x3) * [R t] (3x4) * [ X Y Z 1 ]'

    This is because I need to embed such a K in implementing a ImageBasedRendering algo

    Thanks again
    regards
    --
    Santhosh
    santhosh@gdit.iiit.net

Posting Permissions

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