View Full Version : how to put a 3D object at fixed screen location ?
KC Cheng
03-14-2012, 11:35 AM
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
tonyo_au
03-14-2012, 05:36 PM
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)
KC Cheng
03-14-2012, 07:18 PM
Hi
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
Bruce Wheaton
03-15-2012, 09:52 AM
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
tonyo_au
03-15-2012, 03:47 PM
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
KC Cheng
03-15-2012, 09:30 PM
Hi,
I think I got the big piture, but still need
to try out something ...
Thanks.
KC
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.