title: C++ Opengl render part of an image
body: <p>Let's say i have a method that get a GLuint texture as a parameter and I'd like to render a part of it. Think about a tile set for instance, i want to be able to load a tile set and render parts (tiles) of it when I load my level.</p>
  
  <p>It would be optimal if I somehow would be able to define the height, width, posX and posY in pixel coordinates from the tile set to draw from.</p>
  
  <p>I've been trying for hours now and any help would be appreciated. </p>
  
  <p>Simplified version of how I currently draw a texture:</p>
  
  <pre><code>    void Render::draw(GLuint texture, float posX, float posY, float sizeX, float sizeY) {
  
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
      glAlphaFunc(GL_GREATER,0.1f);
  
      glBindTexture( GL_TEXTURE_2D, texture );
      glPushMatrix();
      glTranslatef(posX,posY,0);
      glBegin( GL_QUADS );
  
      //Bottom-left vertex (corner)
      glTexCoord2i( 0, 0);
      glVertex2f( -sizeX,-sizeY);
      //Bottom-right vertex (corner)
      glTexCoord2i( 1, 0);
      glVertex2f(sizeX,-sizeY);
      //Top-right vertex (corner) 
      glTexCoord2i( 1, 1);
      glVertex2f(sizeX,sizeY);
      //Top-left vertex (corner)
      glTexCoord2i( 0, 1);
      glVertex2f( -sizeX,sizeY);
  
      glEnd();
      glPopMatrix();
      glDisable(GL_BLEND);
  }
  </code></pre>