Search in sources :

Example 1 with Tesselator

use of com.mojang.blaze3d.vertex.Tesselator in project MinecraftForge by MinecraftForge.

the class GuiUtils method drawTexturedModalRect.

public static void drawTexturedModalRect(PoseStack matrixStack, int x, int y, int u, int v, int width, int height, float zLevel) {
    final float uScale = 1f / 0x100;
    final float vScale = 1f / 0x100;
    Tesselator tessellator = Tesselator.getInstance();
    BufferBuilder wr = tessellator.getBuilder();
    wr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
    Matrix4f matrix = matrixStack.last().pose();
    wr.vertex(matrix, x, y + height, zLevel).uv(u * uScale, ((v + height) * vScale)).endVertex();
    wr.vertex(matrix, x + width, y + height, zLevel).uv((u + width) * uScale, ((v + height) * vScale)).endVertex();
    wr.vertex(matrix, x + width, y, zLevel).uv((u + width) * uScale, (v * vScale)).endVertex();
    wr.vertex(matrix, x, y, zLevel).uv(u * uScale, (v * vScale)).endVertex();
    tessellator.end();
}
Also used : Matrix4f(com.mojang.math.Matrix4f) BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) Tesselator(com.mojang.blaze3d.vertex.Tesselator)

Example 2 with Tesselator

use of com.mojang.blaze3d.vertex.Tesselator 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 3 with Tesselator

use of com.mojang.blaze3d.vertex.Tesselator 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 Tesselator (com.mojang.blaze3d.vertex.Tesselator)3 GameRenderer (net.minecraft.client.renderer.GameRenderer)2 Matrix4f (com.mojang.math.Matrix4f)1