PDA

View Full Version : glviewport query



jyoti
07-09-2009, 04:28 AM
Can any1 tell me y we need to use glViewport. I am not very clear with its usage.

Giancarlo
07-09-2009, 04:43 AM
The viewport is like the canvas of a paint. Once u define how big is the Frame of your paint (corresponding to the border of the window) you need to define how big is ur canvas where ur going to draw. that's the viewport. That's why it always defined in the reshape function.

jyoti
07-09-2009, 04:50 AM
hi

that means that it is the area made available for drawing purposes.
Drawing using opengl cant be done outside this portion , rite?
But why do we need it in reshape function of window?

Giancarlo
07-09-2009, 04:55 AM
yes potentially is the area in Pixel which defines where u can draw with OpenGL.

Usually is callled in the reshape as the reshape event is the very first one occuring as soon as the window is creted. Suddenly followed by the display one.

So calling the glViewport(0,0,w,h) makes sure that u always define a viewport. it's also important in case you change dimensions of the windows. it lets you openGL to update the viewport with the new dimensions.

_NK47
07-09-2009, 05:02 AM
if you remember old games like doom, duke nukem, etc. you could always decrease/increase the viewport size to get better framerates, also the image looked smaller. viewport can be any size you want but it makes too much sense if its the size of your window (also when window is resized).

Hlz
07-09-2009, 06:16 AM
I remember having to reduce the viewport to the size of postage stamp to play Quake on my old 486 (woot!). It was a bit like peering through a keyhole (not that I ever have), but mighty fun none the less.

ZbuffeR
07-09-2009, 08:59 AM
doing that in the original Doom, down to the smaller possible size, a message appeared "buy a 486 !" :p

jyoti
07-10-2009, 12:54 AM
Hi
Thanx ppl for ur replies.

Is the purpose of the configure event also to adjust the size of viewport whenever the window is resized?Does it have any other purpose?Is it always required to have a callback written for this event?

jyoti
07-10-2009, 04:59 AM
Hi

can anyone tell me where the coordinate (0,0)is located on the window ? I am getting confused with the negative values used for the first two parameters passed in glviewport function.Similarly when we use negative values for functions like glrectf what does it mean?

Hlz
07-10-2009, 06:24 AM
That sort of depends on your transformation matrices.

If you have a projection matrix that maps the unit square to the entirety of the viewport, like

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, viewportWidth, 0, viewportHeight, -1, 1);

then a view space (0, 0) would be mapped to the lower left hand corner of the screen, whereas

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, viewportWidth, viewportHeight, 0, -1, 1);

would map (0, 0) to the upper left corner, and so on.