glViewport() and more

Started by
3 comments, last by diddly-yo 21 years, 10 months ago
What exactly (ok, not exactly, just generally) does the glViewport() command do? I have tried playing around with it, but I can''t seem to understand what it does. I read the documentation on msdn, but I am unclear on a few (read: many) things. When it refers to "affine coordinates" and "normalized device coordinates," what is it talking about? Thanks, diddly
Advertisement
Basically you are just restricting opengl to change pixels in the rectangle defined in the glViewport call. For example if you want the top half of the screen to be a front view of something and the bottom half to be the rear view you could implement it as two separate rendering contexts or you can use one context but split the screen with two calls to glViewport.

// using a 800X600 pixel rendering context
// draw on top part of screen
glViewport(0,0,800,300);
drawFrontView();
// draw on bottom part of screen
glViewport(0,300,800,300);
drawRearView();


The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
Thank you very much!

diddly
another question on this topic...

if I want to create a rear view mirror, do i use glViewport like this?

glViewport( full screen coords)

draw( all stuff thats full screen)

glViewport( coords of rear-view)

draw(rear view mirror reflection)

Thanks!
Perhaps I was a little vague in my description. glViewport is kind of like setting up a new context to render into. In other words you will fit the entire scene that would have normally appeared in fullscree/window into the new viewport. If you make your viewport tall and skinny all your wolrd objects will also be tall and skinny because that is how the coordinates will be mapped onto the screen. So you could use it to do a rearview mirror but you would have to make sure your perspective/frustrum is correct or your objects will appear small. I think glScissor is usually used for rearview mirrors. That way you don''t have to monkey with the correct scaling, you just change the direction of your frustum to face aft and only let it draw inside the scissor fence.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson

This topic is closed to new replies.

Advertisement