tags:

views:

213

answers:

2

I made a window sized 800x600. I called

gluOrtho2D(-400,400,-300,300);
glViewport(400,300,400,300);

and I drew a line from (-100,-100) to (100,100). I think I should see a line from (0,0) to (100,100), but I am getting the whole line. Why is this?

+4  A: 

glViewport doesn't cause any clipping. Normally, all drawing is clipped to the window. Since you have asked OpenGL to draw into a region of your window, you will need to also tell OpenGL to clip coordinates outside this viewport. For that, you will need glScissor.

In addition, your math is wrong. Your projection matrix is 800 units wide by 600 units tall, centered at (0, 0). This is then mapped to a portion of the window that is 400 pixels wide by 300 pixels tall, in the upper-right corner of the window.

If you draw a line from (-100, -100) to (100, 100), it will extend across only a small part of your viewing frustrum. The frustrum is sized to fit in the viewport.

In the image, the blue box is the window, and the red box represents the viewport. The black line should be the line that you drew.

An image describing what the paragraph says.

Hope that helps!

Daniel Yankowsky
Ya thanks for the reply...................i think i am getting the hang of it
codemax
Yep. This stuff can be tricky at first. Eventually, you'll find it to be second nature.
Daniel Yankowsky
A: 

glViewport describes the area of your window which will be drawn by OpenGL. glOrtho or gluOrtho2D define a unit system (OpenGL units) which fit into that (via glViewport defined) area. So your line will be drawn within the Viewport from -100,-100 to 100,100

penguinpower
Thanks for the reply.........kinda got it
codemax