title: Rendering sprites from spritesheet with OpenGL?
body: <p>Imagine the following scenario: you have a set of RPG character spritesheets in PNG format and you want to use them in an OpenGL application.</p>
  
  <p>The separate characters are (usually) 16 by 24 pixels in size (that is, 24 pixels tall) and may be at any width and height without leaving padding. Kinda like this:</p>
  
  <p><a href="https://i.stack.imgur.com/H8BdO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H8BdO.png" alt="Terra, from Final Fantasy VI"></a><br>
  <sub>(source: <a href="http://helmet.kafuka.org/terra.net/nomura/Terra.png" rel="nofollow noreferrer">kafuka.org</a>)</sub>  </p>
  
  <p>I already have the code to determine an integer-based clipping rectangle given a frame index and size:</p>
  
  <pre><code>int framesPerRow = sheet.Width / cellWidth;
  int framesPerColumn = sheet.Height / cellHeight;
  framesTotal = framesPerRow * framesPerColumn;
  int left = frameIndex % framesPerRow;
  int top = frameIndex / framesPerRow;
  //Clipping rect's width and height are obviously cellWidth and cellHeight.
  </code></pre>
  
  <p>Running this code with <code>frameIndex = 11, cellWidth = 16, cellHeight = 24</code> would return a cliprect <code>(32, 24)-(48, 48)</code> assuming it's Right/Bottom opposed to Width/Height.</p>
  
  <p><strong>The actual question</strong></p>
  
  <p>Now, given a clipping rectangle and an X/Y coordinate to place the sprite on, how do I draw this in OpenGL? Having the zero coordinate in the <em>top</em> left is preferred.</p>