Zooming in 2D editor

Hi there!

I’m making a 2D paint program, much like MS Paint (it’s a school project, not of free will). I can draw lines, circles and polygons. All objects drawn are saved in a linked list, so they are properly redrawn when a reshape occurs. I’ve made a zoom function which uses the mouse to draw a rectangle around the object and then zooms in:

gluOrtho2D(zx1,x ,y , zy1);
glViewport(x, y, zx1-x, zy1-y);

where zx1,zy1 are the top-left coordinates and x,y the bottom-right coordinates of the rectangle.
But when I try to draw a line after this, the lines doesn’t appear at the same position as the mouse is. Why? My coordinate system is set up with 0,0 at the top-left of the window.
How do I zoom out again?

Thankful for answer!


You have to adjust your mouse-coordinates when you zoomed in. Assuming you zoomed by factor 2.0, you have to divide your mouse-coordinates by 2.0 before you use them for creating a new line.