SHARE
TWEET

Untitled

a guest Dec 26th, 2014 163 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void drawSpriteSheet(Texture t, int x, int y, int width, int height, int frameXNum, int frameYNum, int frame)
  2.         {
  3.                 int w = t.getImageWidth();
  4.                 int h = t.getImageHeight();
  5.  
  6.                 int x1 = w / frameXNum;
  7.                 int y1 = h / frameYNum;
  8.  
  9.                 int lx = ((frame % frameXNum) * x1) - x1;
  10.                 int ly = ((int) Math.floor(frame / frameXNum) * y1);
  11.                 int lw = x1;
  12.                 int lh = y1;
  13.  
  14.                 t.bind();
  15.  
  16.                 glBegin(GL_TRIANGLES);
  17.  
  18.                 glTexCoord2f((lx / w) + (lw / w), ly / h);
  19.                 glVertex2i(x + width, y);
  20.                 glTexCoord2f(lx / w, ly / h);
  21.                 glVertex2i(x, y);
  22.                 glTexCoord2f(lx / w, (ly / h) + (lh / h));
  23.                 glVertex2i(x, y + height);
  24.  
  25.                 glTexCoord2f(lx / w, (ly / h) + (lh / h));
  26.                 glVertex2i(x, y + height);
  27.                 glTexCoord2f((lx / w) + (lw / w), (ly / h) + (lh / h));
  28.                 glVertex2i(x + width, y + height);
  29.                 glTexCoord2f((lx / w) + (lw / w), ly / h);
  30.                 glVertex2i(x + width, y);
  31.  
  32.                 glEnd();
  33.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top