# The Industry's Foundation for High Performance Graphics

1. ## Zoom with OpenGL

Hi, I'm a new user of OpenGL.
This is what I have to do: I have got a variable x that can increase or decrease.
I would like to know how to increase/decrease the dimensions of each polygons I have drawn by increasing/decreasing the value of the variable x.

2. You can use glScalef(x, x, x) or the modelview matrix for to do this

3. I followed your advice and I used glScaled(1.0003, 1.0003, 1.0003). The problem is that the dimensions of the polygons increase indefinitely and the polygons become so big that I cannot see them in window. What I want to do is to increase the size of polygons at a specified rate (for example to double the size) such as a common "zoom". I would be very grateful if you can tell me what is wrong with that.

4. What are you exactly trying to achieve? If you want a binoculars-like zoom that affects everything, you can do this by decreasing the field of view in projection matrix. For example, if you are using glu, you could use gluPerspective(fieldOfView * zoomFactor, aspectRatio, zNear);

If you want to use glScale to scale each of the objects individually, you should do it like this:

Code :
```glPushMatrix(); // save the current matrix
glScalef(scaleX, scaleY, scaleZ); // scale the matrix
drawObject(); // draw the object(s) that need to be scaled
glPopMatrix(); // load the unscaled matrix```

5. OK, I try to explane better: I drew six polygons that form a parallelepiped.
I have got the variable x, initially the value of x is 0, but as I said before, the variable can increase or decrease.
Now image that x increases (for example the new value of x is 2), it means that I have to move two units along the z axis and see the object grow. Instead if x decreases (for example it become -3) I have to move three units along the z-axis (in the opposite direction respect to the previous) and see the object shrink.
I hope you've understood all, Google translate is not perfect XD.

6. Ah, so you don't actually want to change the size of the object, you only want to move closer/further so that the object looks smaller/larger? In that case my previous example still works, just replace glScalef with glTranslatef(0, 0, x). In OpenGL the camera never moves, only the objects can be moved around. If you want to move forward on the z-axis, you will have to move all the objects backwards on the z-axis instead.

7. Yes yes, I have understood my problem. But I don't know where I am wronging, I have written the function glTranslatef(0, 0, x) but it doesn't work very well. I see the object for a moment and after it sparish from the camera. Have I write something else before/after I call the fuction glTranslatef(0, 0, x)?

8. Once an object gets less that near plane (or greater than the far plane) it will disappear. Set you near value to something like 0.1 to view the object for as long as possible.

9. What is the command to do that? And have I to write it before or after the command glTranslatef?

10. Originally Posted by disa89
I see the object for a moment and after it sparish from the camera. Have I write something else before/after I call the fuction glTranslatef(0, 0, x)?
Like I mentioned, you should use glPushMatrix() and glPopMatrix(), see the code example I posted above (replace glScalef with glTranslatef).
For setting the near / far plane, you can use gluPerspective(fieldOfView, aspectRatio, closePlane, farPlane) in case you are using glut.

If you did both things mentioned above and are still having trouble please post your source so we don't have to guess what is wrong. I would also recommend you to find a good tutorial that goes through all the basics or perhaps even a book, that would help you a lot with the basics.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•