Skip to content

Instantly share code, notes, and snippets.

@TeamDman
Created August 18, 2020 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TeamDman/29b8d520c8511dd36f3b73950755c9c0 to your computer and use it in GitHub Desktop.
Save TeamDman/29b8d520c8511dd36f3b73950755c9c0 to your computer and use it in GitHub Desktop.
Drawing transparent textures that are otherwise opqaue
public void drawTextureRaw(
MatrixStack matrixStack, int x, int y,
int srcX, int srcY, int w, int h, int r, int g, int b, int a
) {
RenderSystem.enableBlend();
RenderSystem.disableAlphaTest();
Matrix4f matrix = matrixStack.getLast().getMatrix();
int blitOffset = getBlitOffset();
BufferBuilder bufferbuilder = Tessellator.getInstance().getBuffer();
bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX);
bufferbuilder.pos(matrix, (float) x, (float) (y + h), (float) blitOffset)
.color(r,g,b,a)
.tex(((float) srcX + 0.0F) / (float) 256, ((float) srcY + (float) h) / (float) 256)
.endVertex();
bufferbuilder.pos(matrix, (float) (x + w), (float) (y + h), (float) blitOffset)
.color(r,g,b,a)
.tex(((float) srcX + (float) w) / (float) 256, ((float) srcY + (float) h) / (float) 256)
.endVertex();
bufferbuilder.pos(matrix, (float) (x + w), (float) y, (float) blitOffset)
.color(r,g,b,a)
.tex(((float) srcX + (float) w) / (float) 256, ((float) srcY + 0.0F) / (float) 256)
.endVertex();
bufferbuilder.pos(matrix, (float) x, (float) y, (float) blitOffset)
.color(r,g,b,a)
.tex(((float) srcX + 0.0F) / (float) 256, ((float) srcY + 0.0F) / (float) 256)
.endVertex();
bufferbuilder.finishDrawing();
RenderSystem.enableAlphaTest();
WorldVertexBufferUploader.draw(bufferbuilder);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment