PDA

View Full Version : zoom implementation



new-to-opengl
09-30-2013, 10:12 PM
Hello,
I am new to opengl . I am using opengl with Qt ,my problem is , i am making a quad and trying to implement zoomin and zoomout option .
but i have some doubts , and need help.
1. i tried with scalef () .. is it the right approach to implement that or i need to use glulookat () or any other function for zoom implementation???
2. when i am using scalef() , the object moves with the zoomfactor.. how to scale an object around its own axis..

here is the code of paintGL() function :

void glwidget::resizeGL(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,1.01,300.01);
glMatrixMode(GL_MODELVIEW);

}

void glwidget:: paintGL()
{

glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

gluLookAt(0,0,50,
0,0,0,
0,1,0);
glPushMatrix();
glScalef(zoomfactor,zoomfactor,1);
//glTranslatef(-zoomfactor,-zoomfactor,1);
glBegin(GL_QUADS);
glVertex3f(200,200,0);
glVertex3f(250,200,0);
glVertex3f(250,250,0);
glVertex3f(200,250,0);
glEnd();
glPopMatrix();

}

where should i change in code so that it shows proper zooming ...

Thanks in Advance