title: Resize only a part of texture, OpenGL
body: <p>I'm working on GUI in OpenGL. I'm using this image to texture my button:
  <img src="https://i.stack.imgur.com/RZbKw.png" alt="enter image description here"></p>
  
  <p>You can't see it very well, but it has a light border (2 pixels width) around it.</p>
  
  <p>What I want to achieve is to have nicely resizable button which keeps it's borders untouched. According to hints given me here, on StackOverflow I decided to use 9-cell-pattern, so I divided my quad into 9 parts like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Ahsbf.png" alt="enter image description here"></p>
  
  <p>I really like an effect I achieved if it goes about borders, but the problem is with a quad that is in the center (9th):</p>
  
  <p><img src="https://i.stack.imgur.com/TkSbL.png" alt="enter image description here"></p>
  
  <p>I would like to repeat or wrap a texture like I do but with ignoring borders. </p>
  
  <p>So my question is - is there any way to do this with only one texture which I'm using now? Or should I create second texture, which would be decreased by a border width and to render this quad in the middle with this texture?</p>
  
  <p>Also I don't know if it's necessary, but I'm putting here a fragment of my code:</p>
  
  <p>This is a code I'm using for tiling/wrapping a texture:</p>
  
  <pre><code>switch(m_bTiling)
  {
  case true:
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                       GL_REPEAT );
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                       GL_REPEAT );
      break;
  case false:
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                       GL_CLAMP );
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                       GL_CLAMP );
      break;
  }
  </code></pre>
  
  <p>And here is a code to draw quads:</p>
  
  <pre><code>// Top left quad [1]
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(0.0f, 1.0-maxTexCoordBorderY);                     
      glVertex2i(pos.x, pos.y + m_borderWidth);
  
      // Top left
      glTexCoord2f(0.0f, 1.0);    
      glVertex2i(pos.x, pos.y);
  
      // Top right
      glTexCoord2f(maxTexCoordBorderX, 1.0);  
      glVertex2i(pos.x + m_borderWidth, pos.y);
  
      // Bottom right
      glTexCoord2f(maxTexCoordBorderX, 1.0-maxTexCoordBorderY);
      glVertex2i(pos.x + m_borderWidth, pos.y + m_borderWidth);
  glEnd();
  
  // Top middle quad [2]
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(maxTexCoordBorderX, 1.0 - maxTexCoordBorderY);             
      glVertex2i(pos.x + m_borderWidth, pos.y + m_borderWidth);
  
      // Top left
      glTexCoord2f(maxTexCoordBorderX, 1.0);
      glVertex2i(pos.x + m_borderWidth, pos.y);
  
      // Top right
      glTexCoord2f(maxTexCoordWidth - maxTexCoordBorderX, 1.0);   
      glVertex2i(pos.x + width - m_borderWidth, pos.y);
  
      // Bottom right
      glTexCoord2f(maxTexCoordWidth - maxTexCoordBorderX, 1.0 - maxTexCoordBorderY);
      glVertex2i(pos.x + width - m_borderWidth, pos.y + m_borderWidth);
  glEnd();
  
  // Top right quad [3]
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(1.0 - maxTexCoordBorderX, 1.0 - maxTexCoordBorderY);                   
      glVertex2i(pos.x + width - m_borderWidth, pos.y + m_borderWidth);
  
      // Top left
      glTexCoord2f(1.0 - maxTexCoordBorderX, 1.0);
      glVertex2i(pos.x + width - m_borderWidth, pos.y);
  
      // Top right
      glTexCoord2f(1.0, 1.0); 
      glVertex2i(pos.x + width, pos.y);
  
      // Bottom right
      glTexCoord2f(1.0, 1.0 - maxTexCoordBorderY);    
      glVertex2i(pos.x + width, pos.y + m_borderWidth);
  glEnd();
  
  // Middle left quad [4]
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(0.0, maxTexCoordBorderY);              
      glVertex2i(pos.x, pos.y + height - m_borderWidth);
  
      // Top left
      glTexCoord2f(0.0, maxTexCoordHeight - maxTexCoordBorderY);
      glVertex2i(pos.x, pos.y + m_borderWidth);
  
      // Top right
      glTexCoord2f(maxTexCoordBorderX, maxTexCoordHeight - maxTexCoordBorderY);           
      glVertex2i(pos.x + m_borderWidth, pos.y + m_borderWidth);
  
      // Bottom right
      glTexCoord2f(maxTexCoordBorderX, maxTexCoordBorderY);
      glVertex2i(pos.x + m_borderWidth, pos.y + height - m_borderWidth);
  glEnd();
  
  // Middle right quad [5] 
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(1.0 - maxTexCoordBorderX, maxTexCoordBorderY);                     
      glVertex2i(pos.x + width - m_borderWidth, pos.y + height - m_borderWidth);
  
      // Top left
      glTexCoord2f(1.0 - maxTexCoordBorderX, maxTexCoordHeight - maxTexCoordBorderY);
      glVertex2i(pos.x + width - m_borderWidth, pos.y + m_borderWidth);
  
      // Top right
      glTexCoord2f(1.0, maxTexCoordHeight - maxTexCoordBorderY);  
      glVertex2i(pos.x + width, pos.y + m_borderWidth);
  
      // Bottom right 
      glTexCoord2f(1.0, maxTexCoordBorderY);  
      glVertex2i(pos.x + width, pos.y + height - m_borderWidth);
  glEnd();
  
  // Bottom left quad [6]
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(0.0, 0.0);                     
      glVertex2i(pos.x, pos.y + height);
  
      // Top left
      glTexCoord2f(0.0, maxTexCoordBorderY);  
      glVertex2i(pos.x, pos.y + height - m_borderWidth);
  
      // Top right
      glTexCoord2f(maxTexCoordBorderX, maxTexCoordBorderY);   
      glVertex2i(pos.x + m_borderWidth, pos.y + height - m_borderWidth);
  
      // Bottom right
      glTexCoord2f(maxTexCoordBorderX, 0.0);  
      glVertex2i(pos.x + m_borderWidth, pos.y + height);
  glEnd();
  
  // Bottom middle quad [7]
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(maxTexCoordBorderX, 0.0);                          
      glVertex2i(pos.x + m_borderWidth, pos.y + height);
  
      // Top left
      glTexCoord2f(maxTexCoordBorderX, maxTexCoordBorderY);
      glVertex2i(pos.x + m_borderWidth, pos.y + height - m_borderWidth);
  
      // Top right
      glTexCoord2f(maxTexCoordWidth - maxTexCoordBorderX, maxTexCoordBorderY);    
      glVertex2i(pos.x + width - m_borderWidth, pos.y + height - m_borderWidth);
  
      // Bottom right
      glTexCoord2f(maxTexCoordWidth - maxTexCoordBorderX, 0.0);   
      glVertex2i(pos.x + width - m_borderWidth, pos.y + height);
  glEnd();
  
  // Bottom right quad [8]
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(1.0 - maxTexCoordBorderX, 0.0);                        
      glVertex2i(pos.x + width - m_borderWidth, pos.y + height);
  
      // Top left
      glTexCoord2f(1.0 - maxTexCoordBorderX, maxTexCoordBorderY);
      glVertex2i(pos.x + width - m_borderWidth, pos.y + height - m_borderWidth);
  
      // Top right
      glTexCoord2f(1.0, maxTexCoordBorderY);  
      glVertex2i(pos.x + width, pos.y + height - m_borderWidth);
  
      // Bottom right 
      glTexCoord2f(1.0, 0.0);
      glVertex2i(pos.x + width, pos.y + height);
  glEnd();
  
  // Middle middle quad [9]
  glBegin(GL_QUADS);
      // Bottom left
      glTexCoord2f(maxTexCoordBorderX, maxTexCoordBorderY);                   
      glVertex2i(pos.x + m_borderWidth, pos.y + height - m_borderWidth);
  
      // Top left
      glTexCoord2f(maxTexCoordBorderX, maxTexCoordHeight - maxTexCoordBorderY);   
      glVertex2i(pos.x + m_borderWidth, pos.y + m_borderWidth);
  
      // Top right
      glTexCoord2f(maxTexCoordWidth - maxTexCoordBorderX, maxTexCoordHeight - maxTexCoordBorderY);        
      glVertex2i(pos.x + width - m_borderWidth, pos.y + m_borderWidth);
  
      // Bottom right 
      glTexCoord2f(maxTexCoordWidth - maxTexCoordBorderX, maxTexCoordBorderY);
      glVertex2i(pos.x + width - m_borderWidth, pos.y + height - m_borderWidth);
  glEnd();
  </code></pre>