Search in sources :

Example 31 with VertexBuffer

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

the class AnimationModelBase method render.

@SuppressWarnings("unchecked")
@Override
public void render(Entity entity, float limbSwing, float limbSwingSpeed, float timeAlive, float yawHead, float rotationPitch, float scale) {
    IAnimationStateMachine capability = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
    if (capability == null) {
        return;
    }
    Pair<IModelState, Iterable<Event>> pair = capability.apply(timeAlive / 20);
    handleEvents((T) entity, timeAlive / 20, pair.getRight());
    IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
    IBakedModel bakedModel = model.bake(pair.getLeft(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
    BlockPos pos = new BlockPos(entity.posX, entity.posY + entity.height, entity.posZ);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.pushMatrix();
    GlStateManager.rotate(180, 0, 0, 1);
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer VertexBuffer = tessellator.getBuffer();
    VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    VertexBuffer.setTranslation(-0.5, -1.5, -0.5);
    lighter.setParent(new VertexBufferConsumer(VertexBuffer));
    lighter.setWorld(entity.world);
    lighter.setState(Blocks.AIR.getDefaultState());
    lighter.setBlockPos(pos);
    boolean empty = true;
    List<BakedQuad> quads = bakedModel.getQuads(null, null, 0);
    if (!quads.isEmpty()) {
        lighter.updateBlockInfo();
        empty = false;
        for (BakedQuad quad : quads) {
            quad.pipe(lighter);
        }
    }
    for (EnumFacing side : EnumFacing.values()) {
        quads = bakedModel.getQuads(null, side, 0);
        if (!quads.isEmpty()) {
            if (empty)
                lighter.updateBlockInfo();
            empty = false;
            for (BakedQuad quad : quads) {
                quad.pipe(lighter);
            }
        }
    }
    // debug quad
    /*VertexBuffer.pos(0, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 0).lightmap(240, 0).endVertex();
        VertexBuffer.pos(0, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 1).lightmap(240, 0).endVertex();
        VertexBuffer.pos(1, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 1).lightmap(240, 0).endVertex();
        VertexBuffer.pos(1, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 0).lightmap(240, 0).endVertex();*/
    VertexBuffer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBufferConsumer(net.minecraftforge.client.model.pipeline.VertexBufferConsumer) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) IAnimationStateMachine(net.minecraftforge.common.model.animation.IAnimationStateMachine) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 32 with VertexBuffer

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

the class FastTESR method renderTileEntityAt.

@Override
public final void renderTileEntityAt(@Nonnull T te, double x, double y, double z, float partialTicks, int destroyStage) {
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer VertexBuffer = tessellator.getBuffer();
    this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled()) {
        GlStateManager.shadeModel(GL11.GL_SMOOTH);
    } else {
        GlStateManager.shadeModel(GL11.GL_FLAT);
    }
    VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    renderTileEntityFast(te, x, y, z, partialTicks, destroyStage, VertexBuffer);
    VertexBuffer.setTranslation(0, 0, 0);
    tessellator.draw();
    RenderHelper.enableStandardItemLighting();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Example 33 with VertexBuffer

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

the class GuiScrollingList method drawGradientRect.

protected void drawGradientRect(int left, int top, int right, int bottom, int color1, int color2) {
    float a1 = (float) (color1 >> 24 & 255) / 255.0F;
    float r1 = (float) (color1 >> 16 & 255) / 255.0F;
    float g1 = (float) (color1 >> 8 & 255) / 255.0F;
    float b1 = (float) (color1 & 255) / 255.0F;
    float a2 = (float) (color2 >> 24 & 255) / 255.0F;
    float r2 = (float) (color2 >> 16 & 255) / 255.0F;
    float g2 = (float) (color2 >> 8 & 255) / 255.0F;
    float b2 = (float) (color2 & 255) / 255.0F;
    GlStateManager.disableTexture2D();
    GlStateManager.enableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
    GlStateManager.shadeModel(GL11.GL_SMOOTH);
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer VertexBuffer = tessellator.getBuffer();
    VertexBuffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
    VertexBuffer.pos(right, top, 0.0D).color(r1, g1, b1, a1).endVertex();
    VertexBuffer.pos(left, top, 0.0D).color(r1, g1, b1, a1).endVertex();
    VertexBuffer.pos(left, bottom, 0.0D).color(r2, g2, b2, a2).endVertex();
    VertexBuffer.pos(right, bottom, 0.0D).color(r2, g2, b2, a2).endVertex();
    tessellator.draw();
    GlStateManager.shadeModel(GL11.GL_FLAT);
    GlStateManager.disableBlend();
    GlStateManager.enableAlpha();
    GlStateManager.enableTexture2D();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Example 34 with VertexBuffer

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

the class GuiScrollingList method drawScreen.

public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    this.mouseX = mouseX;
    this.mouseY = mouseY;
    this.drawBackground();
    boolean isHovering = mouseX >= this.left && mouseX <= this.left + this.listWidth && mouseY >= this.top && mouseY <= this.bottom;
    int listLength = this.getSize();
    int scrollBarWidth = 6;
    int scrollBarRight = this.left + this.listWidth;
    int scrollBarLeft = scrollBarRight - scrollBarWidth;
    int entryLeft = this.left;
    int entryRight = scrollBarLeft - 1;
    int viewHeight = this.bottom - this.top;
    int border = 4;
    if (Mouse.isButtonDown(0)) {
        if (this.initialMouseClickY == -1.0F) {
            if (isHovering) {
                int mouseListY = mouseY - this.top - this.headerHeight + (int) this.scrollDistance - border;
                int slotIndex = mouseListY / this.slotHeight;
                if (mouseX >= entryLeft && mouseX <= entryRight && slotIndex >= 0 && mouseListY >= 0 && slotIndex < listLength) {
                    this.elementClicked(slotIndex, slotIndex == this.selectedIndex && System.currentTimeMillis() - this.lastClickTime < 250L);
                    this.selectedIndex = slotIndex;
                    this.lastClickTime = System.currentTimeMillis();
                } else if (mouseX >= entryLeft && mouseX <= entryRight && mouseListY < 0) {
                    this.clickHeader(mouseX - entryLeft, mouseY - this.top + (int) this.scrollDistance - border);
                }
                if (mouseX >= scrollBarLeft && mouseX <= scrollBarRight) {
                    this.scrollFactor = -1.0F;
                    int scrollHeight = this.getContentHeight() - viewHeight - border;
                    if (scrollHeight < 1)
                        scrollHeight = 1;
                    int var13 = (int) ((float) (viewHeight * viewHeight) / (float) this.getContentHeight());
                    if (var13 < 32)
                        var13 = 32;
                    if (var13 > viewHeight - border * 2)
                        var13 = viewHeight - border * 2;
                    this.scrollFactor /= (float) (viewHeight - var13) / (float) scrollHeight;
                } else {
                    this.scrollFactor = 1.0F;
                }
                this.initialMouseClickY = mouseY;
            } else {
                this.initialMouseClickY = -2.0F;
            }
        } else if (this.initialMouseClickY >= 0.0F) {
            this.scrollDistance -= ((float) mouseY - this.initialMouseClickY) * this.scrollFactor;
            this.initialMouseClickY = (float) mouseY;
        }
    } else {
        this.initialMouseClickY = -1.0F;
    }
    this.applyScrollLimits();
    Tessellator tess = Tessellator.getInstance();
    VertexBuffer worldr = tess.getBuffer();
    ScaledResolution res = new ScaledResolution(client);
    double scaleW = client.displayWidth / res.getScaledWidth_double();
    double scaleH = client.displayHeight / res.getScaledHeight_double();
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glScissor((int) (left * scaleW), (int) (client.displayHeight - (bottom * scaleH)), (int) (listWidth * scaleW), (int) (viewHeight * scaleH));
    if (this.client.world != null) {
        this.drawGradientRect(this.left, this.top, this.right, this.bottom, 0xC0101010, 0xD0101010);
    } else // Draw dark dirt background
    {
        GlStateManager.disableLighting();
        GlStateManager.disableFog();
        this.client.renderEngine.bindTexture(Gui.OPTIONS_BACKGROUND);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        float scale = 32.0F;
        worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
        worldr.pos(this.left, this.bottom, 0.0D).tex(this.left / scale, (this.bottom + (int) this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
        worldr.pos(this.right, this.bottom, 0.0D).tex(this.right / scale, (this.bottom + (int) this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
        worldr.pos(this.right, this.top, 0.0D).tex(this.right / scale, (this.top + (int) this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
        worldr.pos(this.left, this.top, 0.0D).tex(this.left / scale, (this.top + (int) this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
        tess.draw();
    }
    int baseY = this.top + border - (int) this.scrollDistance;
    if (this.hasHeader) {
        this.drawHeader(entryRight, baseY, tess);
    }
    for (int slotIdx = 0; slotIdx < listLength; ++slotIdx) {
        int slotTop = baseY + slotIdx * this.slotHeight + this.headerHeight;
        int slotBuffer = this.slotHeight - border;
        if (slotTop <= this.bottom && slotTop + slotBuffer >= this.top) {
            if (this.highlightSelected && this.isSelected(slotIdx)) {
                int min = this.left;
                int max = entryRight;
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                GlStateManager.disableTexture2D();
                worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
                worldr.pos(min, slotTop + slotBuffer + 2, 0).tex(0, 1).color(0x80, 0x80, 0x80, 0xFF).endVertex();
                worldr.pos(max, slotTop + slotBuffer + 2, 0).tex(1, 1).color(0x80, 0x80, 0x80, 0xFF).endVertex();
                worldr.pos(max, slotTop - 2, 0).tex(1, 0).color(0x80, 0x80, 0x80, 0xFF).endVertex();
                worldr.pos(min, slotTop - 2, 0).tex(0, 0).color(0x80, 0x80, 0x80, 0xFF).endVertex();
                worldr.pos(min + 1, slotTop + slotBuffer + 1, 0).tex(0, 1).color(0x00, 0x00, 0x00, 0xFF).endVertex();
                worldr.pos(max - 1, slotTop + slotBuffer + 1, 0).tex(1, 1).color(0x00, 0x00, 0x00, 0xFF).endVertex();
                worldr.pos(max - 1, slotTop - 1, 0).tex(1, 0).color(0x00, 0x00, 0x00, 0xFF).endVertex();
                worldr.pos(min + 1, slotTop - 1, 0).tex(0, 0).color(0x00, 0x00, 0x00, 0xFF).endVertex();
                tess.draw();
                GlStateManager.enableTexture2D();
            }
            this.drawSlot(slotIdx, entryRight, slotTop, slotBuffer, tess);
        }
    }
    GlStateManager.disableDepth();
    int extraHeight = (this.getContentHeight() + border) - viewHeight;
    if (extraHeight > 0) {
        int height = (viewHeight * viewHeight) / this.getContentHeight();
        if (height < 32)
            height = 32;
        if (height > viewHeight - border * 2)
            height = viewHeight - border * 2;
        int barTop = (int) this.scrollDistance * (viewHeight - height) / extraHeight + this.top;
        if (barTop < this.top) {
            barTop = this.top;
        }
        GlStateManager.disableTexture2D();
        worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
        worldr.pos(scrollBarLeft, this.bottom, 0.0D).tex(0.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
        worldr.pos(scrollBarRight, this.bottom, 0.0D).tex(1.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
        worldr.pos(scrollBarRight, this.top, 0.0D).tex(1.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
        worldr.pos(scrollBarLeft, this.top, 0.0D).tex(0.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
        tess.draw();
        worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
        worldr.pos(scrollBarLeft, barTop + height, 0.0D).tex(0.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
        worldr.pos(scrollBarRight, barTop + height, 0.0D).tex(1.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
        worldr.pos(scrollBarRight, barTop, 0.0D).tex(1.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
        worldr.pos(scrollBarLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
        tess.draw();
        worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
        worldr.pos(scrollBarLeft, barTop + height - 1, 0.0D).tex(0.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
        worldr.pos(scrollBarRight - 1, barTop + height - 1, 0.0D).tex(1.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
        worldr.pos(scrollBarRight - 1, barTop, 0.0D).tex(1.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
        worldr.pos(scrollBarLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
        tess.draw();
    }
    this.drawScreen(mouseX, mouseY);
    GlStateManager.enableTexture2D();
    GlStateManager.shadeModel(GL11.GL_FLAT);
    GlStateManager.enableAlpha();
    GlStateManager.disableBlend();
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Example 35 with VertexBuffer

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

the class GuiUtils method drawGradientRect.

public static void drawGradientRect(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;
    GlStateManager.disableTexture2D();
    GlStateManager.enableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    GlStateManager.shadeModel(7425);
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexbuffer = tessellator.getBuffer();
    vertexbuffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
    vertexbuffer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
    vertexbuffer.pos(left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
    vertexbuffer.pos(left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex();
    vertexbuffer.pos(right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex();
    tessellator.draw();
    GlStateManager.shadeModel(7424);
    GlStateManager.disableBlend();
    GlStateManager.enableAlpha();
    GlStateManager.enableTexture2D();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Aggregations

VertexBuffer (net.minecraft.client.renderer.VertexBuffer)52 Tessellator (net.minecraft.client.renderer.Tessellator)50 BlockPos (net.minecraft.util.math.BlockPos)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)5 EnumFacing (net.minecraft.util.EnumFacing)5 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)3 Minecraft (net.minecraft.client.Minecraft)3 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)3 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 Entity (net.minecraft.entity.Entity)3 Vec3i (net.minecraft.util.math.Vec3i)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 FontRenderer (net.minecraft.client.gui.FontRenderer)2 RenderManager (net.minecraft.client.renderer.entity.RenderManager)2 Vec3d (net.minecraft.util.math.Vec3d)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 NotNull (org.jetbrains.annotations.NotNull)2 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1