Search in sources :

Example 1 with GameRenderer

use of net.minecraft.client.renderer.GameRenderer in project MinecraftForge by MinecraftForge.

the class GuiUtils method drawGradientRect.

public static void drawGradientRect(Matrix4f mat, int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) {
    float startAlpha = (float) (startColor >> 24 & 255) / 255.0F;
    float startRed = (float) (startColor >> 16 & 255) / 255.0F;
    float startGreen = (float) (startColor >> 8 & 255) / 255.0F;
    float startBlue = (float) (startColor & 255) / 255.0F;
    float endAlpha = (float) (endColor >> 24 & 255) / 255.0F;
    float endRed = (float) (endColor >> 16 & 255) / 255.0F;
    float endGreen = (float) (endColor >> 8 & 255) / 255.0F;
    float endBlue = (float) (endColor & 255) / 255.0F;
    RenderSystem.enableDepthTest();
    RenderSystem.disableTexture();
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    Tesselator tessellator = Tesselator.getInstance();
    BufferBuilder buffer = tessellator.getBuilder();
    buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
    buffer.vertex(mat, right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
    buffer.vertex(mat, left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
    buffer.vertex(mat, left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex();
    buffer.vertex(mat, right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex();
    tessellator.end();
    RenderSystem.disableBlend();
    RenderSystem.enableTexture();
}
Also used : BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) GameRenderer(net.minecraft.client.renderer.GameRenderer) Tesselator(com.mojang.blaze3d.vertex.Tesselator)

Example 2 with GameRenderer

use of net.minecraft.client.renderer.GameRenderer in project MinecraftForge by MinecraftForge.

the class ScrollPanel method drawBackground.

/**
 * Draws the background of the scroll panel. This runs AFTER Scissors are enabled.
 */
protected void drawBackground(PoseStack matrix, Tesselator tess, float partialTicks) {
    BufferBuilder worldr = tess.getBuilder();
    if (this.client.level != null) {
        this.drawGradientRect(matrix, this.left, this.top, this.right, this.bottom, bgColorFrom, bgColorTo);
    } else // Draw dark dirt background
    {
        RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
        RenderSystem.setShaderTexture(0, GuiComponent.BACKGROUND_LOCATION);
        final float texScale = 32.0F;
        worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
        worldr.vertex(this.left, this.bottom, 0.0D).uv(this.left / texScale, (this.bottom + (int) this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
        worldr.vertex(this.right, this.bottom, 0.0D).uv(this.right / texScale, (this.bottom + (int) this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
        worldr.vertex(this.right, this.top, 0.0D).uv(this.right / texScale, (this.top + (int) this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
        worldr.vertex(this.left, this.top, 0.0D).uv(this.left / texScale, (this.top + (int) this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
        tess.end();
    }
}
Also used : BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) GameRenderer(net.minecraft.client.renderer.GameRenderer)

Example 3 with GameRenderer

use of net.minecraft.client.renderer.GameRenderer in project MinecraftForge by MinecraftForge.

the class ScrollPanel method render.

@Override
public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
    Tesselator tess = Tesselator.getInstance();
    BufferBuilder worldr = tess.getBuilder();
    double scale = client.getWindow().getGuiScale();
    RenderSystem.enableScissor((int) (left * scale), (int) (client.getWindow().getHeight() - (bottom * scale)), (int) (width * scale), (int) (height * scale));
    this.drawBackground(matrix, tess, partialTicks);
    int baseY = this.top + border - (int) this.scrollDistance;
    this.drawPanel(matrix, right, baseY, tess, mouseX, mouseY);
    RenderSystem.disableDepthTest();
    int extraHeight = (this.getContentHeight() + border) - height;
    if (extraHeight > 0) {
        int barHeight = getBarHeight();
        int barTop = (int) this.scrollDistance * (height - barHeight) / extraHeight + this.top;
        if (barTop < this.top) {
            barTop = this.top;
        }
        int barBgAlpha = this.barBgColor >> 24 & 0xff;
        int barBgRed = this.barBgColor >> 16 & 0xff;
        int barBgGreen = this.barBgColor >> 8 & 0xff;
        int barBgBlue = this.barBgColor & 0xff;
        RenderSystem.setShader(GameRenderer::getPositionColorShader);
        RenderSystem.disableTexture();
        worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
        worldr.vertex(barLeft, this.bottom, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
        worldr.vertex(barLeft + barWidth, this.bottom, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
        worldr.vertex(barLeft + barWidth, this.top, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
        worldr.vertex(barLeft, this.top, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
        tess.end();
        int barAlpha = this.barColor >> 24 & 0xff;
        int barRed = this.barColor >> 16 & 0xff;
        int barGreen = this.barColor >> 8 & 0xff;
        int barBlue = this.barColor & 0xff;
        worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
        worldr.vertex(barLeft, barTop + barHeight, 0.0D).color(barRed, barGreen, barBlue, barAlpha).endVertex();
        worldr.vertex(barLeft + barWidth, barTop + barHeight, 0.0D).color(barRed, barGreen, barBlue, barAlpha).endVertex();
        worldr.vertex(barLeft + barWidth, barTop, 0.0D).color(barRed, barGreen, barBlue, barAlpha).endVertex();
        worldr.vertex(barLeft, barTop, 0.0D).color(barRed, barGreen, barBlue, barAlpha).endVertex();
        tess.end();
        int barBorderAlpha = this.barBorderColor >> 24 & 0xff;
        int barBorderRed = this.barBorderColor >> 16 & 0xff;
        int barBorderGreen = this.barBorderColor >> 8 & 0xff;
        int barBorderBlue = this.barBorderColor & 0xff;
        worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
        worldr.vertex(barLeft, barTop + barHeight - 1, 0.0D).color(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha).endVertex();
        worldr.vertex(barLeft + barWidth - 1, barTop + barHeight - 1, 0.0D).color(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha).endVertex();
        worldr.vertex(barLeft + barWidth - 1, barTop, 0.0D).color(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha).endVertex();
        worldr.vertex(barLeft, barTop, 0.0D).color(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha).endVertex();
        tess.end();
    }
    RenderSystem.enableTexture();
    RenderSystem.disableBlend();
    RenderSystem.disableScissor();
}
Also used : BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) GameRenderer(net.minecraft.client.renderer.GameRenderer) Tesselator(com.mojang.blaze3d.vertex.Tesselator)

Aggregations

BufferBuilder (com.mojang.blaze3d.vertex.BufferBuilder)3 GameRenderer (net.minecraft.client.renderer.GameRenderer)3 Tesselator (com.mojang.blaze3d.vertex.Tesselator)2