LordPankake

Rotating Quad-Drawn Images - LWJGL

Nov 27th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. Img: http://b.1339.cf/vvllsst.png
  2.  
  3. //LoadingScreen.java
  4. private void renderUnit(Unit u) {
  5.     int a = (int) u.getAngle();
  6.     int x = u.getX();
  7.     int y = u.getY();
  8.     int w = u.getWidth();
  9.     int h = u.getHeight();
  10.     GL11.glTranslated(w / 2, h / 2, 0);
  11.     GL11.glRotated(a, 0, 0, 1);
  12.     GL11.glTranslated(-w / 2, -h / 2, 0);
  13.     GL11.glRotated(-a, 0, 0, 1);
  14.     GL11.glTranslated(x, y, 0);
  15.     GL11.glRotated(a, 0, 0, 1);
  16.     GL11.glTranslated(-x, -y, 0);
  17.     RenderUtil.renderTexture(x, y, w, h, u.getTextures().getAt(0));
  18. }
  19. //RenderUtil.java
  20. public static void renderTexture(int x, int y, int width, int height, Texture texture) {
  21.     GL11.glEnable(GL11.GL_TEXTURE_2D);
  22.     GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
  23.     GL11.glBegin(GL11.GL_QUADS);
  24.         GL11.glTexCoord2f(0, 0);
  25.         GL11.glVertex2f(x, y);
  26.         GL11.glTexCoord2f(0, 1);
  27.         GL11.glVertex2f(x, y + height);
  28.         GL11.glTexCoord2f(1, 1);
  29.         GL11.glVertex2f(x + width, y + height);
  30.         GL11.glTexCoord2f(1, 0);
  31.         GL11.glVertex2f(x + width, y);
  32.     GL11.glEnd();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment