diff options
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java | 97 |
1 files changed, 13 insertions, 84 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java index 4a343f9e..3305cd13 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java @@ -5,6 +5,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.BackgroundBlur; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; @@ -787,7 +788,6 @@ public class CalendarOverlay { @SubscribeEvent public void onGuiScreenDrawTimer(GuiScreenEvent.BackgroundDrawnEvent event) { - blurBackground(); if(!drawTimerForeground) { drawTimer(); } @@ -903,7 +903,7 @@ public class CalendarOverlay { GlStateManager.disableLighting(); GlStateManager.disableColorMaterial(); - renderBlurredBackground(width, height, guiLeft+3, guiTop+3, xSize-6, ySize-6); + renderBlurredBackground(10, width, height, guiLeft+3, guiTop+3, xSize-6, ySize-6); Minecraft.getMinecraft().getTextureManager().bindTexture(DISPLAYBAR); Utils.drawTexturedRect(guiLeft, guiTop, xSize, 20, GL11.GL_NEAREST); @@ -985,6 +985,13 @@ public class CalendarOverlay { GlStateManager.popMatrix(); } + private void renderBlurredBackground(float blurStrength, int screenWidth, int screenHeight, + int x, int y, int blurWidth, int blurHeight) { + BackgroundBlur.renderBlurredBackground(blurStrength, screenWidth, screenHeight, x, y, blurWidth, blurHeight); + Gui.drawRect(x, y, x+blurWidth, y+blurHeight, 0xc8101010); + GlStateManager.color(1, 1, 1, 1); + } + @SubscribeEvent public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) { if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { @@ -1021,10 +1028,10 @@ public class CalendarOverlay { Utils.drawGradientRect(0, 0, width, height, -1072689136, -804253680); - renderBlurredBackground(width, height, guiLeft+3, guiTop+3, 162, 14); - renderBlurredBackground(width, height, guiLeft+3, guiTop+26, 14, 141); - renderBlurredBackground(width, height, guiLeft+151, guiTop+26, 14, 141); - renderBlurredBackground(width, height, guiLeft+26, guiTop+26, 116, 141); + renderBlurredBackground(10, width, height, guiLeft+3, guiTop+3, 162, 14); + renderBlurredBackground(10, width, height, guiLeft+3, guiTop+26, 14, 141); + renderBlurredBackground(10, width, height, guiLeft+151, guiTop+26, 14, 141); + renderBlurredBackground(10, width, height, guiLeft+26, guiTop+26, 116, 141); Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, GL11.GL_NEAREST); @@ -1381,82 +1388,4 @@ public class CalendarOverlay { return projMatrix; } - private double lastBgBlurFactor = -1; - private void blurBackground() { - if(!OpenGlHelper.isFramebufferEnabled()) return; - - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; - - if(blurOutputHorz == null) { - blurOutputHorz = new Framebuffer(width, height, false); - blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); - } - if(blurOutputVert == null) { - blurOutputVert = new Framebuffer(width, height, false); - blurOutputVert.setFramebufferFilter(GL11.GL_NEAREST); - } - if(blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { - blurOutputHorz.createBindFramebuffer(width, height); - blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); - } - if(blurOutputVert.framebufferWidth != width || blurOutputVert.framebufferHeight != height) { - blurOutputVert.createBindFramebuffer(width, height); - blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); - } - - if(blurShaderHorz == null) { - try { - blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", - Minecraft.getMinecraft().getFramebuffer(), blurOutputHorz); - blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); - blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch(Exception e) { } - } - if(blurShaderVert == null) { - try { - blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", - blurOutputHorz, blurOutputVert); - blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); - blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch(Exception e) { } - } - if(blurShaderHorz != null && blurShaderVert != null) { - if(15 != lastBgBlurFactor) { - blurShaderHorz.getShaderManager().getShaderUniform("Radius").set((float)15); - blurShaderVert.getShaderManager().getShaderUniform("Radius").set((float)15); - lastBgBlurFactor = 15; - } - GL11.glPushMatrix(); - blurShaderHorz.loadShader(0); - blurShaderVert.loadShader(0); - GlStateManager.enableDepth(); - GL11.glPopMatrix(); - - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); - } - } - - /** - * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. - * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] - */ - public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { - if(!OpenGlHelper.isFramebufferEnabled()) return; - - float uMin = x/(float)width; - float uMax = (x+blurWidth)/(float)width; - float vMin = (height-y)/(float)height; - float vMax = (height-y-blurHeight)/(float)height; - - GlStateManager.depthMask(false); - blurOutputVert.bindFramebufferTexture(); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); - blurOutputVert.unbindFramebufferTexture(); - GlStateManager.depthMask(true); - } - } |