content: package me.earth.earthhack.impl.util.render;
  
  import me.earth.earthhack.impl.core.ducks.entity.IEntityRenderer;
  import net.minecraft.client.Minecraft;
  import net.minecraft.client.gui.ScaledResolution;
  import net.minecraft.client.renderer.GlStateManager;
  import net.minecraft.client.renderer.RenderHelper;
  import net.minecraft.client.shader.Framebuffer;
  import org.lwjgl.opengl.Display;
  
  import java.awt.*;
  
  import static org.lwjgl.opengl.GL11.*;
  import static org.lwjgl.opengl.GL20.glUseProgram;
  
  /**
   * @author TheSlowly
   * Rewritten by Megyn, the guy above is a complete moron.
   */
  public abstract class FramebufferShader extends Shader {
  
      private static Framebuffer framebuffer;
      protected static int lastScale;
      protected static int lastScaleWidth;
      protected static int lastScaleHeight;
  
      protected float red, green, blue, alpha = 1F;
      protected float radius = 2F;
      protected float quality = 1F;
  
      private boolean entityShadows;
  
      public FramebufferShader(final String fragmentShader) {
          super(fragmentShader);
      }
  
      public void startDraw(final float partialTicks) {
          GlStateManager.enableAlpha();
  
          GlStateManager.pushMatrix();
          GlStateManager.pushAttrib();
  
          framebuffer = setupFrameBuffer(framebuffer);
          // framebuffer.framebufferClear();
          framebuffer.bindFramebuffer(true);
          entityShadows = mc.gameSettings.entityShadows;
          mc.gameSettings.entityShadows = false;
          ((IEntityRenderer) mc.entityRenderer).invokeSetupCameraTransform(partialTicks, 0);
      }
  
      public void stopDraw(final Color color, final float radius, final float quality, Runnable... shaderOps) {
          mc.gameSettings.entityShadows = entityShadows;
          GlStateManager.enableBlend();
          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          mc.getFramebuffer().bindFramebuffer(true);
  
          red = color.getRed() / 255F;
          green = color.getGreen() / 255F;
          blue = color.getBlue() / 255F;
          alpha = color.getAlpha() / 255F;
          this.radius = radius;
          this.quality = quality;
  
          mc.entityRenderer.disableLightmap();
          RenderHelper.disableStandardItemLighting();
  
          startShader();
          mc.entityRenderer.setupOverlayRendering();
          drawFramebuffer(framebuffer);
          stopShader();
  
          mc.entityRenderer.disableLightmap();
  
          GlStateManager.popMatrix();
          GlStateManager.popAttrib();
      }
  
      /**
       * @param frameBuffer
       * @return frameBuffer
       * @author Megyn
       */
      public Framebuffer setupFrameBuffer(Framebuffer frameBuffer) {
          if (Display.isActive() || Display.isVisible())
          {
              if (frameBuffer != null)
              {
                  frameBuffer.framebufferClear();
                  ScaledResolution scale = new ScaledResolution(Minecraft.getMinecraft());
                  int factor = scale.getScaleFactor();
                  int factor2 = scale.getScaledWidth();
                  int factor3 = scale.getScaledHeight();
                  if (lastScale != factor || lastScaleWidth != factor2 || lastScaleHeight != factor3) {
                      frameBuffer.deleteFramebuffer();
                      frameBuffer = new Framebuffer(mc.displayWidth, mc.displayHeight, true);
                      frameBuffer.framebufferClear();
                  }
                  lastScale = factor;
                  lastScaleWidth = factor2;
                  lastScaleHeight = factor3;
              }
              else
              {
                  frameBuffer = new Framebuffer(mc.displayWidth, mc.displayHeight, true);
              }
          }
          else
          {
              if (frameBuffer == null)
              {
                  frameBuffer = new Framebuffer(mc.displayWidth, mc.displayHeight, true);
              }
          }
  
          return frameBuffer;
      }
  
      /**
       * @author TheSlowly
       */
      public void drawFramebuffer(final Framebuffer framebuffer) {
          final ScaledResolution scaledResolution = new ScaledResolution(mc);
          glBindTexture(GL_TEXTURE_2D, framebuffer.framebufferTexture);
          glBegin(GL_QUADS);
          glTexCoord2d(0, 1);
          glVertex2d(0, 0);
          glTexCoord2d(0, 0);
          glVertex2d(0, scaledResolution.getScaledHeight());
          glTexCoord2d(1, 0);
          glVertex2d(scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight());
          glTexCoord2d(1, 1);
          glVertex2d(scaledResolution.getScaledWidth(), 0);
          glEnd();
          glUseProgram(0); // genius right here!!!1!
      }
  
  }
  