Advertisement
TerrificTable55

Untitled

Nov 13th, 2022
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. public static void bloomCircle(double x, double y, double width, int blurRadius, Color color, boolean cache) {
  2.         GlStateManager.pushAttrib();
  3.         GlStateManager.pushMatrix();
  4.         GlStateManager.alphaFunc(516, 0.01f);
  5.         double height = width;
  6.         height = Math.max(0, height);
  7.         width = Math.max(0, width);
  8.         width += blurRadius * 2;
  9.         height += blurRadius * 2;
  10.         x -= blurRadius;
  11.         y -= blurRadius;
  12.         final float _X = (float) (x - 0.25f);
  13.         final float _Y = (float) (y + 0.25f);
  14.         final int identifier = (int) (width * height + width + color.hashCode() * blurRadius + blurRadius);
  15.         GL11.glEnable(3553);
  16.         GL11.glDisable(2884);
  17.         GL11.glEnable(3008);
  18.         GL11.glEnable(3042);
  19.         if (shadowCache.containsKey(identifier) && cache) {
  20.             final int texId = shadowCache.get(identifier);
  21.             GlStateManager.bindTexture(texId);
  22.         }
  23.         else {
  24.             final BufferedImage original = new BufferedImage((int) width, (int) height, 2);
  25.             final Graphics g = original.getGraphics();
  26.             g.setColor(color);
  27.             for (int i=0; i < 4; i++) {
  28.                 g.fillArc(blurRadius, blurRadius, (int) (width - blurRadius * 2), (int) (height - blurRadius * 2), i*90, i*90 + 90);
  29.             }
  30.             g.dispose();
  31.             final GaussianFilter op = new GaussianFilter((float)blurRadius);
  32.             final BufferedImage blurred = op.filter(original, null);
  33.             final int texId = TextureUtil.uploadTextureImageAllocate(TextureUtil.glGenTextures(), blurred, true, false);
  34.             shadowCache.put(identifier, texId);
  35.         }
  36.         GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  37.         GL11.glBegin(7);
  38.         GL11.glTexCoord2f(0.0f, 0.0f);
  39.         GL11.glVertex2d(_X, _Y);
  40.         GL11.glTexCoord2f(0.0f, 1.0f);
  41.         GL11.glVertex2d(_X, _Y + height);
  42.         GL11.glTexCoord2f(1.0f, 1.0f);
  43.         GL11.glVertex2d(_X + width, _Y + height);
  44.         GL11.glTexCoord2f(1.0f, 0.0f);
  45.         GL11.glVertex2d(_X + width, _Y);
  46.         GL11.glEnd();
  47.         GL11.glDisable(3553);
  48.         GL11.glEnable(2884);
  49.         GL11.glDisable(3008);
  50.         GL11.glDisable(3042);
  51.         GlStateManager.popAttrib();
  52.         GlStateManager.popMatrix();
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement