Skip to content

Commit

Permalink
ScreenDrawing: Fix texturedRect not respecting alpha values
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Sep 27, 2023
1 parent f719ee5 commit 502805b
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public static void texturedRect(DrawContext context, int x, int y, int width, in
float r = (color >> 16 & 255) / 255.0F;
float g = (color >> 8 & 255) / 255.0F;
float b = (color & 255) / 255.0F;
RenderSystem.setShaderColor(r, g, b, opacity);
float a = (color >> 24 & 255) / 255.0F;
RenderSystem.enableBlend();
RenderSystem.setShaderColor(r, g, b, opacity * a);

outer: if (texture.u1() == 0 && texture.u2() == 1 && texture.v1() == 0 && texture.v2() == 1) {
// If we're drawing the full texture, just let vanilla do it.
Expand Down Expand Up @@ -150,6 +152,7 @@ public static void texturedRect(DrawContext context, int x, int y, int width, in
matrices.pop();
}

RenderSystem.disableBlend();
// Don't let the color cause tinting to other draw calls.
RenderSystem.setShaderColor(1, 1, 1, 1);
}
Expand Down Expand Up @@ -180,12 +183,13 @@ public static void texturedRect(DrawContext context, int x, int y, int width, in
float r = (color >> 16 & 255) / 255.0F;
float g = (color >> 8 & 255) / 255.0F;
float b = (color & 255) / 255.0F;
float a = (color >> 24 & 255) / 255.0F;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
Matrix4f model = context.getMatrices().peek().getPositionMatrix();
RenderSystem.enableBlend();
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShaderColor(r, g, b, opacity);
RenderSystem.setShaderColor(r, g, b, opacity * a);
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
buffer.vertex(model, x, y + height, 0).texture(u1, v2).next();
Expand Down

0 comments on commit 502805b

Please sign in to comment.