View Full Version : Viewport position and scaling affects objects?
11-15-2009, 08:59 AM
Why do objects within the viewport translate and scale when I change the position of the viewport and scale it? I am only changing the x,y,w,h of glViewport, not the objects.
There is a rectangle that is drawn inside the viewport to frame the viewport window. This rectangle is drawn in the display() function, where the objects are also drawn.
When I change the x, the rectangle moves left or right, when I change the y the rectangle moves up or down. But so does the object inside the viewport.
Same thing with the viewport size changing w and h.
Can anyone explain why? And, how can I fix this?
11-15-2009, 10:50 AM
what you are describing is exactly what viewport is expected to do. Are you trying to use the viewport to zoom and pan? glViewport will NOT work for that. The viewport only sets the mapping to the final pixels that are drawn to in your window. For illustration, if you want to map everything to the entire window you call glVeiwport(0,0,w,h) but if you want to map the same exact scene but to the upper right half window only you call glVeiwport(w/2,h/2,w/2,h/2). In other words glViewport affects EVERYTHING you draw equally and just controls where they all end up in the final window pixel coordinates. Typically you only set glViewport once and only once.
Can you explain further what you are trying to do? Are you trying to move a rectangle around the scene but have the objects stay fixed?
11-15-2009, 11:11 AM
first of all thanks for your reply.
Not really trying to use the viewport to zoom or pan, just to view objects. However, I am expected to be able to move the viewport and change its size without affecting the object.
First, the viewport should start with a rectangle that will allow me to see the boundries of the viewport. And, a partial view of the object.
Then, I should be able to move the viewport up, including the rectangle, and see more of the object drawn, but the object cannot move up.
I have read the Blue Book definitions and many other tutorial explanations, but I still cannot understand clearly how one thing affects the other if I am only changing the properties of the viewport.
Thanks for your help.
11-15-2009, 12:18 PM
I am not usually one for semantics but in this case you need to be careful in using the term viewport -- in openGL it has a specific meaning of mapping the entire scene to a portion of the window in pixel coordinates. What I think you really are referring to is the model view. You really want to move the "model view" and change its size without affecting the object.
I suggest running the following examples to see how gluLookAt and openGL matrices interact:
The matrixModelView.zip and matrixProjection.zip at the bottom of songho tutorials (http://www.songho.ca/opengl/gl_transform.html) .
And projection.exe and transformation.exe included in the Windows binary zip file at GameDev Tutors (http://www.gamedev.net/reference/articles/article839.asp). You may need the data.zip file also. Or in Linux, like me, just compile the code manually.
Notice that glViewport is not used explicitly in changing the viewing volume and direction! That is what the MOVELVIEW PROJECTION matrix stacks are for.
Once you run those try reading the Redbook Chapter 3 (http://glprogramming.com/red/chapter03.html). I have both the BlueBook and the Redbook -- in my _opinion_ Redbook has a better explanation.
11-15-2009, 06:28 PM
Try the scissor test:
// draw commands here
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.