Search in sources :

Example 66 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project Railcraft by Railcraft.

the class RenderStair method renderItem.

@Override
public void renderItem(RenderBlocks renderBlocks, ItemStack item, ItemRenderType renderType) {
    Block block = getBlock();
    int meta = item.getItemDamage();
    renderBlocks.setRenderBoundsFromBlock(block);
    Tessellator tess = Tessellator.instance;
    for (int k = 0; k < 2; ++k) {
        if (k == 0)
            renderBlocks.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.5D);
        if (k == 1)
            renderBlocks.setRenderBounds(0.0D, 0.0D, 0.5D, 1.0D, 0.5D, 1.0D);
        OpenGL.glTranslatef(-0.5F, -0.5F, -0.5F);
        tess.startDrawingQuads();
        tess.setNormal(0.0F, -1.0F, 0.0F);
        renderBlocks.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderBlocks.getBlockIconFromSideAndMetadata(block, 0, meta));
        tess.draw();
        tess.startDrawingQuads();
        tess.setNormal(0.0F, 1.0F, 0.0F);
        renderBlocks.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderBlocks.getBlockIconFromSideAndMetadata(block, 1, meta));
        tess.draw();
        tess.startDrawingQuads();
        tess.setNormal(0.0F, 0.0F, -1.0F);
        renderBlocks.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderBlocks.getBlockIconFromSideAndMetadata(block, 2, meta));
        tess.draw();
        tess.startDrawingQuads();
        tess.setNormal(0.0F, 0.0F, 1.0F);
        renderBlocks.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderBlocks.getBlockIconFromSideAndMetadata(block, 3, meta));
        tess.draw();
        tess.startDrawingQuads();
        tess.setNormal(-1.0F, 0.0F, 0.0F);
        renderBlocks.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderBlocks.getBlockIconFromSideAndMetadata(block, 4, meta));
        tess.draw();
        tess.startDrawingQuads();
        tess.setNormal(1.0F, 0.0F, 0.0F);
        renderBlocks.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderBlocks.getBlockIconFromSideAndMetadata(block, 5, meta));
        tess.draw();
        OpenGL.glTranslatef(0.5F, 0.5F, 0.5F);
    }
    renderBlocks.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) Block(net.minecraft.block.Block)

Example 67 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project Railcraft by Railcraft.

the class RenderSwitch method renderItem.

@Override
public void renderItem(RenderBlocks renderblocks, ItemStack item, ItemRenderType renderType) {
    switch(renderType) {
        case EQUIPPED:
        case EQUIPPED_FIRST_PERSON:
        case ENTITY:
            float scale = 1.5f;
            OpenGL.glScalef(scale, scale, scale);
    }
    // Core
    setTextureCore();
    float min = 4.0F * PIX;
    float max = 12.0F * PIX;
    info.setBlockBounds(min, 0.0F, min, max, 5.0F * PIX, max);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    // Post
    min = 7.0F * PIX;
    max = 9.0F * PIX;
    info.setBlockBounds(min, 0.0F, min, max, 8.0F * PIX, max);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    info.setBlockBounds(min, 11.0F * PIX, min, max, 12.0F * PIX, max);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    // Extensions
    setTextureExtension();
    info.setBlockBounds(6.0F * PIX, 0.0F, 0.0F, 10.0F * PIX, 3.0F * PIX, 1.0F);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    // Red target
    setTextureRed();
    info.setBlockBounds(4.0F * PIX, 8.0F * PIX, 7.0F * PIX, 8.0F * PIX, 11.0F * PIX, 8.0F * PIX);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    info.setBlockBounds(8.0F * PIX, 8.0F * PIX, 8.0F * PIX, 12.0F * PIX, 11.0F * PIX, 9.0F * PIX);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    info.setBlockBounds(12.0F * PIX, 9.0F * PIX, 8.0F * PIX, 13.0F * PIX, 10.0F * PIX, 9.0F * PIX);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    info.setBlockBounds(3.0F * PIX, 8.0F * PIX, 7.0F * PIX, 4.0F * PIX, 9.0F * PIX, 8.0F * PIX);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    info.setBlockBounds(3.0F * PIX, 10.0F * PIX, 7.0F * PIX, 4.0F * PIX, 11.0F * PIX, 8.0F * PIX);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    // White target
    setTextureWhite();
    info.setBlockBounds(8.0F * PIX, 8.0F * PIX, 4.0F * PIX, 9.0F * PIX, 11.0F * PIX, 8.0F * PIX);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    info.setBlockBounds(7.0F * PIX, 8.0F * PIX, 8.0F * PIX, 8.0F * PIX, 11.0F * PIX, 12.0F * PIX);
    RenderFakeBlock.renderBlockOnInventory(renderblocks, info, 1);
    // Lever
    if (type == EnumSignal.SWITCH_LEVER) {
        Tessellator tess = Tessellator.instance;
        tess.startDrawingQuads();
        renderLever(-0.5, -0.5, -0.5, 3, false);
        tess.draw();
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator)

Example 68 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project Railcraft by Railcraft.

the class LocomotiveRendererDefault method renderLocomotive.

//    @Override
//    public IIcon[] getItemIcons() {
//        return itemIcons;
//    }
//
//    @Override
//    public void registerItemIcons(IIconRegister iconRegister) {
//        String tag = "railcraft:locomotives/" + MiscTools.cleanTag(modelTag);
//        itemIcons[0] = iconRegister.registerIcon(tag + ".primary");
//        itemIcons[1] = iconRegister.registerIcon(tag + ".secondary");
//        itemIcons[2] = iconRegister.registerIcon(tag + ".nocolor");
//    }
@Override
public void renderLocomotive(ICartRenderer renderer, EntityMinecart cart, int primaryColor, int secondaryColor, @Nullable ResourceLocation emblemTexture, float light, float time) {
    OpenGL.glPushMatrix();
    OpenGL.glPushAttrib(GL11.GL_ENABLE_BIT);
    //        OpenGL.glEnable(GL11.GL_BLEND);
    //        OpenGL.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    OpenGL.glScalef(-1F, -1F, 1.0F);
    color[0] = primaryColor;
    color[1] = secondaryColor;
    for (int pass = 0; pass < textures.length; pass++) {
        renderer.bindTex(textures[pass]);
        int c = color[pass];
        float dim = 1.0F;
        float c1 = (float) (c >> 16 & 255) / 255.0F;
        float c2 = (float) (c >> 8 & 255) / 255.0F;
        float c3 = (float) (c & 255) / 255.0F;
        OpenGL.glColor4f(c1 * dim, c2 * dim, c3 * dim, SeasonPlugin.isGhostTrain(cart) ? 0.5F : 1);
        model.render(cart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    }
    OpenGL.glPopAttrib();
    if (emblemTexture != null) {
        renderer.bindTex(emblemTexture);
        Tessellator tess = Tessellator.getInstance();
        VertexBuffer vertexBuffer = tess.getBuffer();
        //            float size = 0.22F;
        //            float offsetX = -0.25F;
        //            float offsetY = -0.25F;
        //            float offsetZ = -0.46F;
        // TODO: Test this!
        vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        vertexBuffer.pos(emblemOffsetX - emblemSize, emblemOffsetY - emblemSize, emblemOffsetZ).tex(0, 0).endVertex();
        vertexBuffer.pos(emblemOffsetX - emblemSize, emblemOffsetY + emblemSize, emblemOffsetZ).tex(0, 1).endVertex();
        vertexBuffer.pos(emblemOffsetX + emblemSize, emblemOffsetY + emblemSize, emblemOffsetZ).tex(1, 1).endVertex();
        vertexBuffer.pos(emblemOffsetX + emblemSize, emblemOffsetY + -emblemSize, emblemOffsetZ).tex(1, 0).endVertex();
        vertexBuffer.pos(emblemOffsetX + emblemSize, emblemOffsetY + -emblemSize, -emblemOffsetZ).tex(0, 0).endVertex();
        vertexBuffer.pos(emblemOffsetX + emblemSize, emblemOffsetY + emblemSize, -emblemOffsetZ).tex(0, 1).endVertex();
        vertexBuffer.pos(emblemOffsetX - emblemSize, emblemOffsetY + emblemSize, -emblemOffsetZ).tex(1, 1).endVertex();
        vertexBuffer.pos(emblemOffsetX - emblemSize, emblemOffsetY - emblemSize, -emblemOffsetZ).tex(1, 0).endVertex();
        tess.draw();
    }
    //        OpenGL.glDisable(GL11.GL_BLEND);
    OpenGL.glPopMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Example 69 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project Railcraft by Railcraft.

the class TESRSignals method doRenderAspect.

protected void doRenderAspect(double x, double y, double z) {
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexBuffer = tessellator.getBuffer();
    final float depth = 1.95F * RenderTools.PIXEL;
    OpenGL.glPushMatrix();
    // no idea why this is necessary, but without it the texture brightness varies depending on what is on screen
    GL11.glNormal3f(0.0F, 0.0F, 1.0F);
    OpenGL.glEnable(GL11.GL_LIGHTING);
    OpenGL.glColor3f(1, 1, 1);
    OpenGL.glTranslated(x, y, z);
    Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    if (lampInfo.glow)
        RenderTools.setBrightness(0.875F);
    vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
    if (lampInfo.sides[2].render) {
        TextureAtlasSprite texture = lampInfo.sides[2].texture;
        vertexBuffer.pos(0, 0, depth).tex(texture.getInterpolatedU(16), texture.getInterpolatedV(16)).endVertex();
        vertexBuffer.pos(0, 1, depth).tex(texture.getInterpolatedU(16), texture.getInterpolatedV(0)).endVertex();
        vertexBuffer.pos(1, 1, depth).tex(texture.getInterpolatedU(0), texture.getInterpolatedV(0)).endVertex();
        vertexBuffer.pos(1, 0, depth).tex(texture.getInterpolatedU(0), texture.getInterpolatedV(16)).endVertex();
    }
    if (lampInfo.sides[3].render) {
        TextureAtlasSprite texture = lampInfo.sides[3].texture;
        vertexBuffer.pos(0, 0, 1 - depth).tex(texture.getInterpolatedU(0), texture.getInterpolatedV(16)).endVertex();
        vertexBuffer.pos(1, 0, 1 - depth).tex(texture.getInterpolatedU(16), texture.getInterpolatedV(16)).endVertex();
        vertexBuffer.pos(1, 1, 1 - depth).tex(texture.getInterpolatedU(16), texture.getInterpolatedV(0)).endVertex();
        vertexBuffer.pos(0, 1, 1 - depth).tex(texture.getInterpolatedU(0), texture.getInterpolatedV(0)).endVertex();
    }
    if (lampInfo.sides[4].render) {
        TextureAtlasSprite texture = lampInfo.sides[4].texture;
        vertexBuffer.pos(depth, 0, 0).tex(texture.getInterpolatedU(0), texture.getInterpolatedV(16)).endVertex();
        vertexBuffer.pos(depth, 0, 1).tex(texture.getInterpolatedU(16), texture.getInterpolatedV(16)).endVertex();
        vertexBuffer.pos(depth, 1, 1).tex(texture.getInterpolatedU(16), texture.getInterpolatedV(0)).endVertex();
        vertexBuffer.pos(depth, 1, 0).tex(texture.getInterpolatedU(0), texture.getInterpolatedV(0)).endVertex();
    }
    if (lampInfo.sides[5].render) {
        TextureAtlasSprite texture = lampInfo.sides[5].texture;
        vertexBuffer.pos(1 - depth, 0, 0).tex(texture.getInterpolatedU(16), texture.getInterpolatedV(16)).endVertex();
        vertexBuffer.pos(1 - depth, 1, 0).tex(texture.getInterpolatedU(16), texture.getInterpolatedV(0)).endVertex();
        vertexBuffer.pos(1 - depth, 1, 1).tex(texture.getInterpolatedU(0), texture.getInterpolatedV(0)).endVertex();
        vertexBuffer.pos(1 - depth, 0, 1).tex(texture.getInterpolatedU(0), texture.getInterpolatedV(16)).endVertex();
    }
    tessellator.draw();
    if (lampInfo.glow)
        RenderTools.resetBrightness();
    lampInfo.resetSidesAndLight();
    OpenGL.glPopMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite)

Example 70 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project Railcraft by Railcraft.

the class TESRTurbineGauge method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileSteamTurbine turbine, double x, double y, double z, float partialTicks, int destroyStage) {
    if (!turbine.isStructureValid() || turbine.getPatternMarker() != 'W')
        // not a gauge block
        return;
    // half width of the needle
    double halfWidth = 0.5 / 16;
    // length of the needle (along the center)
    double len = 0.26;
    // offset to prevent z-fighting
    double zOffset = 0.001;
    // average the value over time to smooth the needle
    double value = turbine.mainGauge = (turbine.mainGauge * 14.0 + turbine.getMainGauge()) / 15.0;
    // set the needle angle between 45° (= 0%) and 135° (= 100%)
    double angle = Math.toRadians(90 * value + 45);
    // vector towards the front of the gauge
    int fx = 0, fz = 0;
    // vector to the right when looking at the gauge
    int rx = 0, rz = 0;
    BlockPos patternPos = turbine.getPatternPosition();
    if (turbine.getPatternIndex() == 0) {
        if (patternPos.getX() == 1) {
            fx = -1;
            rz = 1;
        } else if (patternPos.getX() == 2) {
            x++;
            z++;
            fx = 1;
            rz = -1;
        }
    } else if (turbine.getPatternIndex() == 1)
        if (patternPos.getZ() == 1) {
            x++;
            fz = -1;
            rx = -1;
        } else if (patternPos.getZ() == 2) {
            z++;
            fz = 1;
            rx = 1;
        }
    if (fx == 0 && fz == 0 || rx == 0 && rz == 0)
        throw new IllegalStateException("can't detect gauge orientation");
    // fix lightmap coords to use the brightness value in front of the block, not inside it (which would be just 0)
    int lmCoords = turbine.getWorld().getCombinedLight(turbine.getPos().add(fx, 0, fz), 0);
    int lmX = lmCoords % 65536;
    int lmY = lmCoords / 65536;
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lmX / 1.0F, lmY / 1.0F);
    OpenGL.glDisable(GL11.GL_TEXTURE_2D);
    OpenGL.glDisable(GL11.GL_LIGHTING);
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexBuffer = tessellator.getBuffer();
    vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
    // move the origin to the center of the gauge
    vertexBuffer.setTranslation(x + rx * 0.5 + fx * zOffset, y + 0.5, z + rz * 0.5 + fz * zOffset);
    double cosA = Math.cos(angle);
    double sinA = Math.sin(angle);
    // displacement along the length of the needle
    double glx = cosA * len;
    double gly = sinA * len;
    // displacement along the width of the needle
    double gwx = sinA * halfWidth;
    double gwy = cosA * halfWidth;
    // half width of the horizontal needle part where it connects to the "case"
    double baseOffset = 1. / Math.sin(angle) * halfWidth;
    // set the needle color to dark-ish red
    int red = 100;
    int green = 0;
    int blue = 0;
    int alpha = 255;
    vertexBuffer.pos(-rx * baseOffset, 0, -rz * baseOffset).color(red, green, blue, alpha).endVertex();
    vertexBuffer.pos(rx * baseOffset, 0, rz * baseOffset).color(red, green, blue, alpha).endVertex();
    vertexBuffer.pos(-rx * glx + rx * gwx, gly + gwy, -rz * glx + rz * gwx).color(red, green, blue, alpha).endVertex();
    vertexBuffer.pos(-rx * glx - rx * gwx, gly - gwy, -rz * glx - rz * gwx).color(red, green, blue, alpha).endVertex();
    tessellator.draw();
    // resetting
    vertexBuffer.setTranslation(0, 0, 0);
    OpenGL.glEnable(GL11.GL_LIGHTING);
    OpenGL.glEnable(GL11.GL_TEXTURE_2D);
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Tessellator (net.minecraft.client.renderer.Tessellator)298 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)50 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)49 ResourceLocation (net.minecraft.util.ResourceLocation)15 Block (net.minecraft.block.Block)13 IIcon (net.minecraft.util.IIcon)13 BlockPos (net.minecraft.util.math.BlockPos)12 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)10 Vec3d (net.minecraft.util.math.Vec3d)9 WorldRenderer (net.minecraft.client.renderer.WorldRenderer)8 EnumFacing (net.minecraft.util.EnumFacing)8 Icon (net.minecraft.util.Icon)8 Random (java.util.Random)7 FontRenderer (net.minecraft.client.gui.FontRenderer)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 World (net.minecraft.world.World)7 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)6 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)6 SideOnly (cpw.mods.fml.relauncher.SideOnly)5 IBlockState (net.minecraft.block.state.IBlockState)5