zooming using gluOrtho2D

Hi,

I’m wondering if somebody could help me figure out how to zoom in/out in 2D using gluOrtho2D.
Currently I have glViewport(0, 0, 400, 300) and gluOrtho2D(0.0, 400.0, 0.0, 300.0) but I am uncertain as to how these work together.
So, how might I do this and maintain aspect ratio so the objects in the view don’t get stretched and stay in the center of the window?

Thanks!

To preserve the aspect ratio, the ratio (r-l)/(t-b) for gluOrtho2D() should be equal to w/h for glViewport().

But if you just want to zoom by a specific factor, it’s probably simpler to just apply a glScale() transformation to the projection matrix after gluOrtho2D().