Texture "zooming"

I’m zooming in on a texture w/ something like this…


	zoomFactor = zoomFactor+.1;

	

	if (slider_moving == true){

		if (xvalue <(int)(SLIDER_X_PCT*width)-50) 
		{
			xvalue=(int)(SLIDER_X_PCT*width-50);
		}
		if (xvalue >(int)(SLIDER_X_PCT*width+140))
		{
			xvalue=(int)(SLIDER_X_PCT*width+140);
		}
		
		xhold=xvalue;
		xtemp=xvalue;
		
		//Zoom Code

		glPushMatrix();			
		glTranslatef(width/2, height/2, 0);			
		glScalef(4,4,0);
		glEnable(GL_TEXTURE_RECTANGLE_ARB);			
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);	
		glBindTexture(GL_TEXTURE_RECTANGLE_ARB, slides[0].textureName);		
		
		glBegin(GL_QUADS); 
		{
			glTexCoord2f(0.0, 0.0) ;					
			glVertex2f(x_offset - 50.0,  y_offset + thumb_height - 50);
			glTexCoord2f(0.0, slides[0].image_h_o/zoomFactor);
			glVertex2f(x_offset - 50.0, y_offset - 50 );
			glTexCoord2f(slides[0].image_w_o/zoomFactor, slides[0].image_h_o/zoomFactor) ; 
			glVertex2f(x_offset + thumb_width - 50.0, y_offset - 50.0);
			glTexCoord2f(slides[0].image_w_o/zoomFactor, 0.0);  
			glVertex2f(x_offset + thumb_width - 50.0, y_offset + thumb_height - 50.0);
		} glEnd();	
		glDisable(GL_TEXTURE_RECTANGLE_ARB);
		glPopMatrix();	 

So I’m zooming in by changing the zoomFactor variables. Unfortunately, this does not zoom in on the center of the image (instead, it’s the top left corner, I believe). Any suggestions on how to zoom to the center?

I have an application similar and had this problem also in the beginning.

Now I use

Rendering

glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, WindowWidth, WindowHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;

glOrtho(-WindowWidth/2, WindowWidth/2, -WindowHeight/2, WindowHeight/2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;

glScalef(X, Y, Z);

TC.X1 := 0; TC.Y1 := 0;
TC.X2 := 1; TC.Y2 := 0;
TC.X3 := 1; TC.Y3 := 1;
TC.X4 := 0; TC.Y4 := 1;

DrawQuad(TC, 0, 0, 0, ImageWidth, ImageHeight);

glBindTexture(GL_TEXTURE_2D, 0);
.
.
.

DrawQuad

glBegin(GL_QUADS);
glTexCoord2f(TC.X1, TC.Y1); glVertex3f(X - Width/2, Y - Height/2, -Z);
glTexCoord2f(TC.X2, TC.Y2); glVertex3f(X + Width/2, Y - Height/2, -Z);
glTexCoord2f(TC.X3, TC.Y3); glVertex3f(X + Width/2, Y + Height/2, -Z);
glTexCoord2f(TC.X4, TC.Y4); glVertex3f(X - Width/2, Y + Height/2, -Z);
glEnd;

I hope this helps.

Peter.

>Unfortunately, this does not zoom in on the center of the image
of course …
if yo start yor texCoord with 0, 0 …
if you want zoom in modify all texcoords …
example 1D:
You: 0,1 zoomed 0,0.5
right: 0,1 Zomed 0.25,0.75
sth like that …

  1. IMO it is better not to use GL_TEXTURE_RECTANGLE_ARB, ist a old Extension … not very good, i not recommend it.