How to zoom into a 2D window?

Started by
3 comments, last by greger 22 years, 5 months ago
Hi all. I am making a simple (!) 2d drawing editor and I use a homemade linked list to store all objects and their vertices in. All works fine. Thing is I need to implement a zoom function that lets the user draw a rectangle on the drawing area and then that area is zoomed in on so it covers the whole drawing area. Anyone got it? How do I do this? I am quite new to opengl as you might guess. Has something to do with the viewport and gluOrtho2D I guess.. Thanks!
Advertisement
void glTranslatef(
GLfloat x,
GLfloat y,
GLfloat z
);

void glScalef(
GLfloat x,
GLfloat y,
GLfloat z
);
Er, nicely done, AP.

You''re making a 2D editor in OpenGL? Interesting.

I think you can do what you want to do with gluOrtho2D and gluUnProject.

    void Zoom (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)  {    // World-coordinates.    GLdouble wx1, wy1, wx2, wy2;    GLdouble model[16], proj[16];    GLint view[4];    // Fill in the matrices    glGetDoublev(GL_MODEVIEW_MATRIX, model);    glGetDoublev(GL_PROJECTION_MATRIX, proj);    glGetIntegerv(GL_VIEWPORT);    // Transform the screen-coords into world-coords    gluUnProject(x1, y1, model, proj, viewport, &wx1, &wy1);    gluUnProject(x2, y2, model, proj, viewport, &wx2, &wy2);    // Set up the matrices.    glMatrixMode(GL_PROJECTION);    gluOrtho2D(wx1, wy1, wx2, wy2);    glMatrixMode(GL_MODELVIEW);    gluOrtho2D(wx1, wy1, wx2, wy2);  }  


All your bases belong to us
CoV
Thanks for the reply.

I''m afraid I can''t get it to work though. First of all glUnProject() needs z-parameters aswell so I just put it this way:

gluUnProject(x1, y1, 0, model, proj, view, &wx1, &wy1, &wz1);

where wz1 is defined just like you defined wx1 and wy1;
I did the same thing on next function call. After calling the Zoomfunction I call Display(), is this what I should do? Do I have to call Reshape() aswell with the rectangle''s width and height? Tried both options but nothing at all happens.

Please help again!

Thanks
Perhaps you could translate the screen where the rectangle would be centered, use glScalef(), then render.
The zoom rectangle would have to have the same aspect ratio as the viewport, or the zoomed image would be distorted.
After the aspect ratio is the same, find the ratio :
viewport rect/zoom rect = glScalef() values
Maybe I''m a bit off, but that should get you off in the right direction.

email

Something kinda sad about
the way that things have come to be.
Desensitized to everything.
What became of subtlety?
--Tool

[email=JValentine_13@hotmail.com]contact[/email]

This topic is closed to new replies.

Advertisement