glviewport query

Can any1 tell me y we need to use glViewport. I am not very clear with its usage.

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.


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?

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.

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).

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.

doing that in the original Doom, down to the smaller possible size, a message appeared “buy a 486 !” :stuck_out_tongue:

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?


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?

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

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

glOrtho(0, viewportWidth, viewportHeight, 0, -1, 1);

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