glOrtho vs glViewport for 2d zooming

I was wondering what all you opengl gurus do for 2d zooming. I’ve got an app that draws 2d shapes and I’m using glViewport to zoom but I’m running into integer round off problems with the viewport dimensions when I zoom in too far. I’ve tried scaling but I’m not too happy with this approach and I’m thinking maybe glOrtho is a better choice, i.e. keep a constant viewport and change the orthogrraphic projection parameters. Any suggestions would be much appreciated.

I have searched the archives on this too.

Thanks in advance!

I have always been happy with glScaled so far.

Thanks, glScaled is definitely an option. Does it even make sense to use glViewport and glOrtho to do zoom?

glOrtho make good sense in 2D.

In mfc, to get scroll bars i can make the openGL viewport bigger than the mfc window. However, as I increase the viewport and keep the mfc window the same size i begin to run into round off error/resolution limits when i get the mouse position. In other words the opengl viewport gets really big making it difficult to map the mouse coords. How can this be solved?

whay are you fooling with the viewport? all you need is a scale (glScale*) or a view xform (glOrtho).

the viewport should normally be set to the window dims. dont fool with that.

thanks for the reply, I’m starting to agree with you here, however, it is nice to be able to scroll across a drawing with mfc scroll bars.

i agree, simon, but there a far better ways to accomplish that. a scroll is simply a translation. as a matrix operation, you could use glTranslate*(). or, for an individual vertex, you could simply offset the positions manually on the cpu, its up to you. i like the matrix stuff, because its cheap, and it affects everthing globally, automagically.

I was just looking for the easy way out, big surprise eh!? If I go with glTranslate then I would have to keep track of scroll bar stuff in my code instead of letting mfc do it and the scroll bar increments would need to be scaled with zooms, that just doesn’t seem very elegant. hmmm…

it will allow for huge viewports, far beyond the range of a gl viewport. in my world editor, i use a system just like this to allow the user to navigate a huge 3D world, by zooming and scrolling with mouse clicks, kinda like the quake and unreal editors. i know of no better way to do this. for my texture browser, i just offset individual quads, since its very easy and fast to do, and i need a special layout.

just think of the thumb position as being the origin in the world, and offset or translate everything relative to that. its really quite easy once you get the hang of it.

okay, gluOrtho2D seems a good choice, I keep the viewport fixed as suggested and just move the view volume around with gluOrtho2D. I think this is a good approach since gluOrtho2D eliminates near and far clipping issues for 2d stuff. Now on to picking…

THanks for the help!

your very welcome, simon. good luck!

by the way, gluOrtho2D is really glOrtho in disguise, with near = -1, and far = +1 (just so you know).