Search in sources :

Example 36 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project RPG-Hud by KurodaAkira.

the class HudElement method drawRect.

/**
 * Draws a rectangle on the screen
 *
 * @param posX
 *            the x positon on the screen
 * @param posY
 *            the y positon on the screen
 * @param width
 *            the width of the rectangle
 * @param height
 *            the height of the rectangle
 * @param color
 *            the color of the rectangle
 */
public static void drawRect(MatrixStack ms, int posX, int posY, int width, int height, int color) {
    if (color == -1)
        return;
    float f3;
    if (color <= 0xFFFFFF && color >= 0)
        f3 = 1.0F;
    else
        f3 = (color >> 24 & 255) / 255.0F;
    float f = (color >> 16 & 255) / 255.0F;
    float f1 = (color >> 8 & 255) / 255.0F;
    float f2 = (color & 255) / 255.0F;
    RenderSystem.enableBlend();
    RenderSystem.disableTexture();
    RenderSystem.defaultBlendFunc();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    RenderSystem.disableDepthTest();
    BufferBuilder vertexbuffer = Tessellator.getInstance().getBuffer();
    vertexbuffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    vertexbuffer.vertex(ms.peek().getPositionMatrix(), posX, posY + height, 0).color(f, f1, f2, f3).next();
    vertexbuffer.vertex(ms.peek().getPositionMatrix(), posX + width, posY + height, 0).color(f, f1, f2, f3).next();
    vertexbuffer.vertex(ms.peek().getPositionMatrix(), posX + width, posY, 0).color(f, f1, f2, f3).next();
    vertexbuffer.vertex(ms.peek().getPositionMatrix(), posX, posY, 0).color(f, f1, f2, f3).next();
    vertexbuffer.end();
    BufferRenderer.draw(vertexbuffer);
    RenderSystem.enableTexture();
    RenderSystem.disableBlend();
    RenderSystem.enableDepthTest();
}
Also used : BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 37 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project ImmersivePortalsMod by qouteall.

the class MyRenderHelper method renderScreenTriangle.

static void renderScreenTriangle() {
    GlStateManager.matrixMode(GL_MODELVIEW);
    GlStateManager.pushMatrix();
    GlStateManager.loadIdentity();
    GlStateManager.matrixMode(GL_PROJECTION);
    GlStateManager.pushMatrix();
    GlStateManager.loadIdentity();
    GlStateManager.disableAlphaTest();
    GlStateManager.disableTexture();
    GlStateManager.shadeModel(GL_SMOOTH);
    GL20.glUseProgram(0);
    GL11.glDisable(GL_CLIP_PLANE0);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferbuilder = tessellator.getBufferBuilder();
    bufferbuilder.begin(GL_TRIANGLES, VertexFormats.POSITION_COLOR);
    bufferbuilder.vertex(1, -1, 0).color(255, 255, 255, 255).next();
    bufferbuilder.vertex(1, 1, 0).color(255, 255, 255, 255).next();
    bufferbuilder.vertex(-1, 1, 0).color(255, 255, 255, 255).next();
    bufferbuilder.vertex(-1, 1, 0).color(255, 255, 255, 255).next();
    bufferbuilder.vertex(-1, -1, 0).color(255, 255, 255, 255).next();
    bufferbuilder.vertex(1, -1, 0).color(255, 255, 255, 255).next();
    tessellator.draw();
    GlStateManager.matrixMode(GL_MODELVIEW);
    GlStateManager.popMatrix();
    GlStateManager.matrixMode(GL_PROJECTION);
    GlStateManager.popMatrix();
    GlStateManager.enableAlphaTest();
    GlStateManager.enableTexture();
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder)

Example 38 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project ImmersivePortalsMod by qouteall.

the class ViewAreaRenderer method buildPortalViewAreaTrianglesBuffer.

private static void buildPortalViewAreaTrianglesBuffer(Vec3d fogColor, Portal portal, BufferBuilder bufferbuilder, Vec3d cameraPos, float partialTicks, float layerWidth) {
    // if layerWidth is small, the teleportation will not be seamless
    // counter-clockwise triangles are front-faced in default
    bufferbuilder.begin(GL_TRIANGLES, VertexFormats.POSITION_COLOR);
    Vec3d posInPlayerCoordinate = portal.getPos().subtract(cameraPos);
    if (portal instanceof Mirror) {
        posInPlayerCoordinate = posInPlayerCoordinate.add(portal.getNormal().multiply(-0.001));
    }
    Consumer<Vec3d> vertexOutput = p -> putIntoVertex(bufferbuilder, p, fogColor);
    if (portal.specialShape == null) {
        generateTriangleRectangular(vertexOutput, portal, layerWidth, posInPlayerCoordinate);
    } else {
        generateTriangleSpecial(vertexOutput, portal, layerWidth, posInPlayerCoordinate);
    }
    if (shouldRenderAdditionalBox(portal, cameraPos)) {
        renderAdditionalBox(portal, cameraPos, vertexOutput);
    }
}
Also used : GlStateManager(com.mojang.blaze3d.platform.GlStateManager) GuiLighting(net.minecraft.client.render.GuiLighting) Tessellator(net.minecraft.client.render.Tessellator) Arrays(java.util.Arrays) OFInterface(com.qouteall.immersive_portals.OFInterface) GL_CLIP_PLANE0(org.lwjgl.opengl.GL11.GL_CLIP_PLANE0) CGlobal(com.qouteall.immersive_portals.CGlobal) SpecialPortalShape(com.qouteall.immersive_portals.portal.SpecialPortalShape) Consumer(java.util.function.Consumer) Mirror(com.qouteall.immersive_portals.portal.Mirror) Vec3d(net.minecraft.util.math.Vec3d) Portal(com.qouteall.immersive_portals.portal.Portal) BufferBuilder(net.minecraft.client.render.BufferBuilder) MinecraftClient(net.minecraft.client.MinecraftClient) GL11(org.lwjgl.opengl.GL11) VertexFormats(net.minecraft.client.render.VertexFormats) GL_TRIANGLES(org.lwjgl.opengl.GL11.GL_TRIANGLES) Mirror(com.qouteall.immersive_portals.portal.Mirror) Vec3d(net.minecraft.util.math.Vec3d)

Example 39 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project ImmersivePortalsMod by qouteall.

the class ViewAreaRenderer method drawPortalViewTriangle.

public static void drawPortalViewTriangle(Portal portal) {
    MinecraftClient.getInstance().getProfiler().push("render_view_triangle");
    DimensionRenderHelper helper = CGlobal.clientWorldLoader.getDimensionRenderHelper(portal.dimensionTo);
    Vec3d fogColor = helper.getFogColor();
    // important
    GlStateManager.enableCull();
    // In OpenGL, if you forget to set one rendering state and the result will be abnormal
    // this design is bug-prone (DirectX is better in this aspect)
    GuiLighting.disable();
    GlStateManager.color4f(1, 1, 1, 1);
    GlStateManager.disableFog();
    GlStateManager.disableAlphaTest();
    GlStateManager.disableTexture();
    GlStateManager.shadeModel(GL11.GL_SMOOTH);
    GlStateManager.disableBlend();
    GlStateManager.disableLighting();
    GL11.glDisable(GL_CLIP_PLANE0);
    if (OFInterface.isShaders.getAsBoolean()) {
        fogColor = Vec3d.ZERO;
    }
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferbuilder = tessellator.getBufferBuilder();
    buildPortalViewAreaTrianglesBuffer(fogColor, portal, bufferbuilder, PortalRenderer.mc.gameRenderer.getCamera().getPos(), MyRenderHelper.partialTicks, portal instanceof Mirror ? 0 : 0.45F);
    tessellator.draw();
    GlStateManager.enableCull();
    GlStateManager.enableAlphaTest();
    GlStateManager.enableTexture();
    GlStateManager.enableLighting();
    MinecraftClient.getInstance().getProfiler().pop();
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder) Mirror(com.qouteall.immersive_portals.portal.Mirror) Vec3d(net.minecraft.util.math.Vec3d)

Example 40 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project BedrockIfy by juancarloscp52.

the class AbstractPackScreenMixin method renderHeaderAndBottom.

/**
 * Render top and bottom "dirt" bars when custom rotating background is enabled.
 */
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/pack/PackScreen;drawCenteredText(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)V", ordinal = 0))
private void renderHeaderAndBottom(CallbackInfo info) {
    if (!Bedrockify.getInstance().settings.isCubemapBackgroundEnabled())
        return;
    headerWidth = Objects.requireNonNull(client).getWindow().getScaledWidth();
    headerHeight = client.getWindow().getScaledHeight();
    headerBottom = headerHeight - 51;
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = tessellator.getBuffer();
    RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.client.getTextureManager().bindTexture(DrawableHelper.BACKGROUND_TEXTURE);
    RenderSystem.enableDepthTest();
    RenderSystem.depthFunc(519);
    float tilingSize = 32.0F;
    // Top and bottom bars.
    bufferBuilder.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
    bufferBuilder.vertex(this.headerLeft, this.headerTop, -100.0D).texture(0.0F, (float) this.headerTop / tilingSize).color(64, 64, 64, 255).next();
    bufferBuilder.vertex(this.headerLeft + this.headerWidth, this.headerTop, -100.0D).texture((float) this.headerWidth / tilingSize, (float) this.headerTop / tilingSize).color(64, 64, 64, 255).next();
    bufferBuilder.vertex(this.headerLeft + this.headerWidth, 0.0D, -100.0D).texture((float) this.headerWidth / tilingSize, 0.0F).color(64, 64, 64, 255).next();
    bufferBuilder.vertex(this.headerLeft, 0.0D, -100.0D).texture(0.0F, 0.0F).color(64, 64, 64, 255).next();
    bufferBuilder.vertex(this.headerLeft, this.headerHeight, -100.0D).texture(0.0F, (float) this.headerHeight / tilingSize).color(64, 64, 64, 255).next();
    bufferBuilder.vertex(this.headerLeft + this.headerWidth, this.headerHeight, -100.0D).texture((float) this.headerWidth / tilingSize, (float) this.headerHeight / tilingSize).color(64, 64, 64, 255).next();
    bufferBuilder.vertex(this.headerLeft + this.headerWidth, this.headerBottom, -100.0D).texture((float) this.headerWidth / tilingSize, (float) this.headerBottom / tilingSize).color(64, 64, 64, 255).next();
    bufferBuilder.vertex(this.headerLeft, this.headerBottom, -100.0D).texture(0.0F, (float) this.headerBottom / tilingSize).color(64, 64, 64, 255).next();
    tessellator.draw();
    RenderSystem.depthFunc(515);
    RenderSystem.disableDepthTest();
    RenderSystem.enableBlend();
    RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
    RenderSystem.disableAlphaTest();
    RenderSystem.shadeModel(7425);
    RenderSystem.disableTexture();
    // Top and bottom bar shadows.
    bufferBuilder.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
    bufferBuilder.vertex(this.headerLeft, this.headerTop + 4, 0.0D).texture(0.0F, 1.0F).color(0, 0, 0, 0).next();
    bufferBuilder.vertex(this.headerWidth, this.headerTop + 4, 0.0D).texture(1.0F, 1.0F).color(0, 0, 0, 0).next();
    bufferBuilder.vertex(this.headerWidth, this.headerTop, 0.0D).texture(1.0F, 0.0F).color(0, 0, 0, 255).next();
    bufferBuilder.vertex(this.headerLeft, this.headerTop, 0.0D).texture(0.0F, 0.0F).color(0, 0, 0, 255).next();
    bufferBuilder.vertex(this.headerLeft, this.headerBottom, 0.0D).texture(0.0F, 1.0F).color(0, 0, 0, 255).next();
    bufferBuilder.vertex(this.headerWidth, this.headerBottom, 0.0D).texture(1.0F, 1.0F).color(0, 0, 0, 255).next();
    bufferBuilder.vertex(this.headerWidth, this.headerBottom - 4, 0.0D).texture(1.0F, 0.0F).color(0, 0, 0, 0).next();
    bufferBuilder.vertex(this.headerLeft, this.headerBottom - 4, 0.0D).texture(0.0F, 0.0F).color(0, 0, 0, 0).next();
    tessellator.draw();
    RenderSystem.enableTexture();
    RenderSystem.shadeModel(7424);
    RenderSystem.enableAlphaTest();
    RenderSystem.disableBlend();
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

BufferBuilder (net.minecraft.client.render.BufferBuilder)76 GameRenderer (net.minecraft.client.render.GameRenderer)46 Tessellator (net.minecraft.client.render.Tessellator)44 Matrix4f (net.minecraft.util.math.Matrix4f)18 MatrixStack (net.minecraft.client.util.math.MatrixStack)14 IMatrix4f (dev.hypnotic.utils.mixin.IMatrix4f)9 Color (java.awt.Color)9 RenderLayer (net.minecraft.client.render.RenderLayer)5 Vec3d (net.minecraft.util.math.Vec3d)5 BlockState (net.minecraft.block.BlockState)4 BlockEntity (net.minecraft.block.entity.BlockEntity)4 ChunkOcclusionDataBuilder (net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder)4 FluidState (net.minecraft.fluid.FluidState)4 BlockPos (net.minecraft.util.math.BlockPos)4 Random (java.util.Random)3 BlockRenderManager (net.minecraft.client.render.block.BlockRenderManager)3 ChunkRendererRegion (net.minecraft.client.render.chunk.ChunkRendererRegion)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 Mirror (com.qouteall.immersive_portals.portal.Mirror)2 HashSet (java.util.HashSet)2