# OpenGL Zoom in openGL

This topic is 4462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi can anyone help me with zoom in openGL. I m using orthographic projection. I just need simple zoom in and zoom out.. I m very new to openGL so askign too many questions.

##### Share on other sites
Although I've never actually written a zoom feature in ortho mode, I'm guessing you'll want to adjust the parameters to glOrtho() so as to change the width and height of the view volume; smaller will zoom in, larger will zoom out. If you need more details, you might post the code where you call glOrtho() so we can give you a more concrete example.

Again though, I'm kind of guessing here; perhaps someone else can give a more authorititive answer.

##### Share on other sites
Yes u can use glOrtho and acheive zooming . That will be true zooming and not scaling .

To zoom in
you reduce the distance between the left and right params and top and bottom params to glOrtho
In effect you are reducing the viewing volume and and the size of the near plane , which is still going to be mapped onto your fixed size VIEWPORT , your screen. So u magnify the view!

To zoom out increase the the params mentioned above , you should get the desired effect.

post back if you have a problem understanding what i have said.

##### Share on other sites
My glortho command is as follows:
glOrtho(-1.5, 1.0, -2.0, 0.5, -1.0, 3.5);

and i m doing the following
 case 'o' :	   zoom = zoom  - 0.5;           glMatrixMode(GL_MODELVIEW);	   glOrtho(-1.5 + zoom, 1.0 + zoom, -2.0 + zoom, 0.5 + zoom, -1.0, 3.5);            break;

but im not getting desired result.

##### Share on other sites
Try:
zoom = zoom  - 0.5; // Or whatever you want the step to beglMatrixMode(GL_PROJECTION); // You had GL_MODELVIEWglOrtho(-1.5 + zoom, 1.0 - zoom, -2.0 + zoom, 0.5 - zoom, -1.0, 3.5); // Changed some of the signs here
The results of these particular values (off-center view volume and relatively large zoom step) may or may not work so well, but you can adjust them if necessary.

##### Share on other sites
Ya thanks very much its workign perfectly.....I was wondering like can I adda slide bar to do this instead of pressing keys u know...

##### Share on other sites
Quote:
 Original post by SrinidhiI was wondering like can I adda slide bar to do this instead of pressing keys u know...
OpenGL doesn't offer any built-in GUI support, but there are some free libraries available around the net. For something as simple as a slider though, another option would be to just implement it yourself.

##### Share on other sites
This is how i do it

void	CCamera::zoomIn(){	m_d_left_plane	*=	0.75f;	m_d_right_plane	*=	0.75f;	m_d_top_plane	*=	0.75f;	m_d_bottom_plane	*= 0.75f;        setViewingVolume();}void	CCamera::zoomOut(){	m_d_left_plane	*=	1.33f;	m_d_right_plane	*=	1.33f;	m_d_top_plane	*=	1.33f;	m_d_bottom_plane	*= 1.33f;		setViewingVolume();}

The setViewingVolume function is as below
It does the glOrtho call
void	CCamera::setViewingVolume(){	double	aspect_ratio	=	(double)canvas_width/(double)canvas_height;		glViewport( 0,0,(int)canvas_width , (int )canvas_height );	glMatrixMode( GL_PROJECTION );	glLoadIdentity();	if( canvas_width &gt; canvas_height ){		glOrtho(m_d_left_plane*aspect_ratio,m_d_right_plane*aspect_ratio,m_d_bottom_plane,m_d_top_plane,m_d_near_plane,m_d_far_plane);	}else{		glOrtho(m_d_left_plane,m_d_right_plane,m_d_bottom_plane*aspect_ratio,m_d_top_plane*aspect_ratio,m_d_near_plane,m_d_far_plane);	}	updateZoomFactors();	glMatrixMode( GL_MODELVIEW );		}

##### Share on other sites
thanks GL_coder for the help!!!

##### Share on other sites
you can also just use glRotatef(Zoom, 0, 0, 0); when in ortho mode. However the last translate must be center screen or it will zoom from last tranlate position.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 30
• 41
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631741
• Total Posts
3001980
×