Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1.     /**********************************************************************
  2.      *
  3.      */
  4.     private void updateTexture(String tex, int texTileID, String src, int srcTileID)
  5.     {
  6.         int texID = this.core.renderEngine.getTexture(tex);
  7.  
  8.         BufferedImage img;
  9.         try
  10.         {
  11.             img = this.getImage(src);
  12.         }
  13.         catch(IOException e)
  14.         {
  15.             e.printStackTrace();
  16.             return;
  17.         }
  18.  
  19.         GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, texID);
  20.  
  21.         int w = img.getWidth();
  22.         int h = img.getHeight();
  23.         int imgBuf[] = new int[w * h];
  24.         byte byteBuf[] = new byte[16 * 16 * 4];
  25.         img.getRGB(0, 0, w, h, imgBuf, 0, w);
  26.         int wTiles = w / 16;
  27.         int hTiles = h / 16;
  28.         int sx = (srcTileID % wTiles) * 16;
  29.         int sy = (srcTileID / hTiles) * 16;
  30.         for(int y = 0; y < 16; ++y)
  31.         {
  32.             for(int x = 0; x < 16; ++x)
  33.             {
  34.                 int spos = sx + x + ((sy + y) * w);
  35.                 int dpos = x + (y * 16);
  36.  
  37.                 int a = (imgBuf[spos] >> 24) & 0xff;
  38.                 int r = (imgBuf[spos] >> 16) & 0xff;
  39.                 int g = (imgBuf[spos] >> 8) & 0xff;
  40.                 int b = imgBuf[spos] & 0xff;
  41.                 if((this.core.gameSettings != null) && this.core.gameSettings.anaglyph)
  42.                 {
  43.                     int ra = ((r * 30) + (g * 59) + (b * 11)) / 100;
  44.                     int ga = ((r * 30) + (g * 70)) / 100;
  45.                     int ba = ((r * 30) + (b * 70)) / 100;
  46.                     r = ra;
  47.                     g = ga;
  48.                     b = ba;
  49.                 }
  50.                 byteBuf[(dpos * 4) + 0] = (byte) r;
  51.                 byteBuf[(dpos * 4) + 1] = (byte) g;
  52.                 byteBuf[(dpos * 4) + 2] = (byte) b;
  53.                 byteBuf[(dpos * 4) + 3] = (byte) a;
  54.             }
  55.         }
  56.  
  57.         this.imageData.clear();
  58.         this.imageData.put(byteBuf);
  59.         this.imageData.position(0).limit(byteBuf.length);
  60.         GL11.glTexSubImage2D(3553 /* GL_TEXTURE_2D */, 0, (texTileID % 16) * 16, (texTileID / 16) * 16, 16, 16, 6408 /* GL_RGBA */, 5121 /* GL_UNSIGNED_BYTE */, this.imageData);
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement