Java Code Examples for com.mojang.blaze3d.systems.RenderSystem#blendFuncSeparate()

The following examples show how to use com.mojang.blaze3d.systems.RenderSystem#blendFuncSeparate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScreenDrawing.java    From LibGui with MIT License 6 votes vote down vote up
/**
 * Draws a textured rectangle.
 *
 * @param x         the x coordinate of the box on-screen
 * @param y         the y coordinate of the box on-screen
 * @param width     the width of the box on-screen
 * @param height    the height of the box on-screen
 * @param texture   the Identifier for the texture
 * @param u1        the left edge of the texture
 * @param v1        the top edge of the texture
 * @param u2        the right edge of the texture
 * @param v2        the bottom edge of the texture
 * @param color     a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint
 * @param opacity   opacity of the drawn texture. (0f is fully opaque and 1f is fully visible)
 * @since 2.0.0
 */
public static void texturedRect(int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color, float opacity) {
	MinecraftClient.getInstance().getTextureManager().bindTexture(texture);

	//float scale = 0.00390625F;

	if (width <= 0) width = 1;
	if (height <= 0) height = 1;

	float r = (color >> 16 & 255) / 255.0F;
	float g = (color >> 8 & 255) / 255.0F;
	float b = (color & 255) / 255.0F;
	Tessellator tessellator = Tessellator.getInstance();
	BufferBuilder buffer = tessellator.getBuffer();
	RenderSystem.enableBlend();
	//GlStateManager.disableTexture2D();
	RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
	buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE); //I thought GL_QUADS was deprecated but okay, sure.
	buffer.vertex(x,         y + height, 0).color(r, g, b, opacity).texture(u1, v2).next();
	buffer.vertex(x + width, y + height, 0).color(r, g, b, opacity).texture(u2, v2).next();
	buffer.vertex(x + width, y,          0).color(r, g, b, opacity).texture(u2, v1).next();
	buffer.vertex(x,         y,          0).color(r, g, b, opacity).texture(u1, v1).next();
	tessellator.draw();
	//GlStateManager.enableTexture2D();
	RenderSystem.disableBlend();
}
 
Example 2
Source File: ScreenDrawing.java    From LibGui with MIT License 6 votes vote down vote up
/**
 * Draws an untextured rectangle of the specified RGB color.
 */
public static void coloredRect(int left, int top, int width, int height, int color) {
	if (width <= 0) width = 1;
	if (height <= 0) height = 1;

	float a = (color >> 24 & 255) / 255.0F;
	float r = (color >> 16 & 255) / 255.0F;
	float g = (color >> 8 & 255) / 255.0F;
	float b = (color & 255) / 255.0F;
	Tessellator tessellator = Tessellator.getInstance();
	BufferBuilder buffer = tessellator.getBuffer();
	RenderSystem.enableBlend();
	RenderSystem.disableTexture();
	RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
	buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR); //I thought GL_QUADS was deprecated but okay, sure.
	buffer.vertex(left,         top + height, 0.0D).color(r, g, b, a).next();
	buffer.vertex(left + width, top + height, 0.0D).color(r, g, b, a).next();
	buffer.vertex(left + width, top,          0.0D).color(r, g, b, a).next();
	buffer.vertex(left,         top,          0.0D).color(r, g, b, a).next();
	tessellator.draw();
	RenderSystem.enableTexture();
	RenderSystem.disableBlend();
}
 
Example 3
Source File: ToggleButton.java    From MiningGadgets with MIT License 6 votes vote down vote up
@Override
public void renderButton(int p_renderButton_1_, int p_renderButton_2_, float p_renderButton_3_) {
    Color activeColor = this.enabled ? Color.GREEN : Color.RED;

    RenderSystem.enableBlend();
    RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA.param, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.param, GlStateManager.SourceFactor.ONE.param, GlStateManager.DestFactor.ZERO.param);
    RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA.param, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.param);

    RenderSystem.disableTexture();
    RenderSystem.color4f(activeColor.getRed() / 255f, activeColor.getGreen() / 255f, activeColor.getBlue() / 255f, this.enabled ? .4f : .6f);
    blit(this.x, this.y, 0, 0, this.width, this.height);
    RenderSystem.enableTexture();

    RenderSystem.color4f(1f, 1f, 1f, 1f);
    Minecraft.getInstance().getTextureManager().bindTexture(texture);
    blit(this.x +2, this.y + 5, 0, 0, 16, 16, 16, 16);
}
 
Example 4
Source File: GuiAddBlock.java    From XRay-Mod with GNU General Public License v3.0 6 votes vote down vote up
static void renderPreview(int x, int y, float r, float g, float b) {
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder tessellate = tessellator.getBuffer();
    RenderSystem.enableBlend();
    RenderSystem.disableTexture();
    RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    RenderSystem.color4f(r/255, g/255, b/255, 1);
    tessellate.begin(7, DefaultVertexFormats.POSITION);
    tessellate.pos(x, y, 0.0D).endVertex();
    tessellate.pos(x, y + 45, 0.0D).endVertex();
    tessellate.pos(x + 202, y + 45, 0.0D).endVertex();
    tessellate.pos(x + 202, y, 0.0D).endVertex();
    tessellator.draw();
    RenderSystem.enableTexture();
    RenderSystem.disableBlend();
}
 
Example 5
Source File: DireButton.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
    if (this.visible) {
        FontRenderer fontrenderer = Minecraft.getInstance().fontRenderer;
        Minecraft.getInstance().getTextureManager().bindTexture(WIDGETS_LOCATION);
        RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.isHovered = isMouseOver(mouseX, mouseY);
        RenderSystem.enableBlend();
        RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA.param, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.param, GlStateManager.SourceFactor.ONE.param, GlStateManager.DestFactor.ZERO.param);
        RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA.param, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.param);
        this.blit(this.x, this.y, 0, 46, this.width / 2, this.height);
        this.blit(this.x + this.width / 2, this.y, 200 - this.width / 2, 46, this.width / 2, this.height);


        int bottomToDraw = 2;
        this.blit(this.x, this.y + this.height - bottomToDraw, 0, 66 - bottomToDraw, this.width / 2, bottomToDraw);
        this.blit(this.x + this.width / 2, this.y + this.height - bottomToDraw, 200 - this.width / 2, 66 - bottomToDraw, this.width / 2, bottomToDraw);

        int j = 14737632;

        if (this.packedFGColor != 0) {
            j = this.packedFGColor;
        } else if (!this.active) {
            j = 10526880;
        } else if (this.isHovered) {
            j = 16777120;
        }

        this.drawCenteredString(fontrenderer, this.getMessage(), this.x + this.width / 2, this.y + (this.height - 7) / 2, j);
    }
}