PDA

View Full Version : Viewports



ToddAtWSU
09-27-2005, 05:27 AM
I am working on a project with OpenGL and I want to show a 2D side of a 3D object in the top right corner (1/4) of the screen. I am sure I need to use glViewport, but it doesn't seem to work properly. Right now I have a cube that rotates at 7 degrees about all 3 axes each time the left mouse button is clicked. I have this occuring at the center of the screen with width w and height h. So right now I call glViewport( 0, 0, (GLsizei) w, (GLsizei) h); I thought I should be able to just call glViewport( (GLsizei) (w/2), (GLsizei) (h/2), (GLsizei) w, (GLsizei) h ); to put the object in the top right corner. But this doesn't work as I expected it to. Does anyone have an idea why it will not display properly in the top-right corner. The cube seems to be in the top-right corner of the top-right corner...not the middle of the top-right corner. Thanks for your help!

memfr0b
09-27-2005, 06:22 AM
That's because glViewport takes the viewport's lower left corner and the viewport's size as parameter. So your call shoul look like this:


glViewport(w/2, h/2, w/2, h/2);

ToddAtWSU
09-27-2005, 06:28 AM
Thank you so much! I plan on buying a copy of the Red Book here soon and maybe that would have helped me. I thought you put the lower-left coordinates and the upper-right coordinates in. Thank you so much!!!!!

memfr0b
09-27-2005, 11:17 AM
The manual pages for OpenGL functions are also available online. For example here: GL man-pages (http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/)