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

Thread: how to put a 3D object at fixed screen location ?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    3

    how to put a 3D object at fixed screen location ?

    Hi,

    I'm new to OpenGL. Could someone give me an example
    show me how to put a 3D object (such as axis) at fixed screen
    location (eg. left-bottom corner). And it will not change
    position when window re-size.

    Thanks
    KC

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117

    Re: how to put a 3D object at fixed screen location ?

    You can use glViewport; for example glViewport(0,0,50,50) will set the drawing area to the bottom left corner (0,0) of the window and 50x50 pixels.

    Now if you used the identity matrix for MVP a line from -1,-1 to 1,1 will draw from 0,0 to 50,50 in the window.

    Experiment a bit with this like moving the view port with glViewport(100,100,50,50)

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    3

    Re: how to put a 3D object at fixed screen location ?

    Hi

    Quote Originally Posted by tonyo_au
    You can use glViewport; for example glViewport(0,0,50,50) will set the drawing area to the bottom left corner (0,0) of the window and 50x50 pixels.

    Now if you used the identity matrix for MVP a line from -1,-1 to 1,1 will draw from 0,0 to 50,50 in the window.

    Experiment a bit with this like moving the view port with glViewport(100,100,50,50)

    Thanks for reply. But that's not what I want. I want to have one and only one 3D object at fixed screen location, not the whole scene.

    For example, I want to draw a small xyz-axis which could show
    the orientation of the scene. When I rotate the scene, the small
    xyz-axis will rotate, but it always site at left-bottom corner
    of the window even when window re-sized.


    Regards
    KC

  4. #4
    Intern Contributor
    Join Date
    May 2008
    Location
    USA
    Posts
    99

    Re: how to put a 3D object at fixed screen location ?

    Quote Originally Posted by KC Cheng
    For example, I want to draw a small xyz-axis which could show
    the orientation of the scene. When I rotate the scene, the small
    xyz-axis will rotate, but it always site at left-bottom corner
    of the window even when window re-sized.
    Generally, you would draw your fixed item separately. Draw your 3D scene with whatever orientation you need, then set things up again, and draw your locked object on top.

    Bruce

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117

    Re: how to put a 3D object at fixed screen location ?

    Thanks for adding that Bruce

    I should have been more clear

    glViewport(0,0,window_width,window_height);

    render scene

    glViewport(0,0,50,50);
    glDisable(GL_DEPTH_TEST); // if you want axes on top

    render xyz-axes

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    3

    Re: how to put a 3D object at fixed screen location ?

    Hi,

    I think I got the big piture, but still need
    to try out something ...
    Thanks.

    KC

Posting Permissions

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