title: LWJGL OpenGL sprite sheet
body: <p>I am new to OpenGL and am currently trying to render a cube with four faces, each with a different texture.</p>
  
  <p>As you all know, having a separate texture for each face type is very memory intensive and makes the application slow.</p>
  
  <p>At the moment I am trying to use a texture sheet for the sprite. I have the graphic file with each texture 16x16 pixels with 256 sprites arranged in a square (16x16).</p>
  
  <p>I know that</p>
  
  <pre><code>GL11.glTexCoord2f(1.0f, 0.0f);
  GL11.glVertex3f(1.0f, 1.0f,  1.0f);
  GL11.glTexCoord2f(0.0f, 0.0f);
  GL11.glVertex3f(0.0f, 1.0f, 1.0f);
  GL11.glTexCoord2f(0.0f, 1.0f);
  GL11.glVertex3f(0.0f, 0.0f, 1.0f);
  GL11.glTexCoord2f(1.0f, 1.0f);
  GL11.glVertex3f(1.0f, 0.0f, 1.0f);
  </code></pre>
  
  <p>gives me a rectangle with the whole sprite sheet so <code>u</code> and <code>v</code> of <code>glTexCoord2f</code> <strong>have</strong> to be less than 1.0f.</p>
  
  <p>What I need now is a formula which will calculate the <code>u</code> and <code>v</code> of any sprite id in the texture.</p>
  
  <p>The IDs go as following in the texture bitmap:</p>
  
  <pre><code>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  17 18 16 20 21 22 23 24...
  </code></pre>
  
  <p>and I'd like to have a <code>u</code> and <code>v</code> for any of these IDs. The last bit isn't explained very well, so I'll explain it better if you would like.</p>
  
  <p>Thank you in advance!</p>