Results 1 to 3 of 3

Thread: Texture "zooming"

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2008
    Posts
    11

    Texture "zooming"

    I'm zooming in on a texture w/ something like this...
    Code :
    	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?

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    17

    Re: Texture "zooming"

    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.

  3. #3
    Member Contributor
    Join Date
    Oct 2001
    Location
    Germany
    Posts
    60

    Re: Texture "zooming"

    >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 ...

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


Similar Threads

  1. Replies: 5
    Last Post: 01-05-2019, 12:13 PM
  2. Switching between "arcball" and "fps-style" camera rotation
    By bsabiston in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-31-2017, 12:37 PM
  3. egl gles2 "function is no-op" "Mesa: User error"
    By unixmania in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-17-2013, 05:30 AM
  4. Replies: 1
    Last Post: 10-26-2012, 02:19 AM
  5. "best" linux dist for a "Gelato" render farm?
    By ArtificialArtOfficial in forum OpenGL: Linux
    Replies: 10
    Last Post: 12-23-2007, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean