Search in sources :

Example 96 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project Minechem by iopleke.

the class RenderHelper method drawTextureIn3D.

/**
     * Draws a texture in 3D using {@link net.minecraft.client.renderer.ItemRenderer#renderItemIn2D(net.minecraft.client.renderer.Tessellator, float, float, float, float, int, int, float)}
     *
     * @param texture the {@link net.minecraft.util.IIcon}
     */
public static void drawTextureIn3D(IIcon texture) {
    Tessellator tessellator = Tessellator.instance;
    float scale = 0.7F;
    GL11.glPushMatrix();
    GL11.glScalef(scale, scale, scale);
    GL11.glTranslatef(-scale / 2, -scale / 2, 0.0F);
    ItemRenderer.renderItemIn2D(tessellator, texture.getMaxU(), texture.getMinV(), texture.getMinU(), texture.getMaxV(), texture.getIconWidth(), texture.getIconHeight(), .0625F);
    GL11.glPopMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator)

Example 97 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project Minechem by iopleke.

the class RenderHelper method drawScaledTexturedRectUV.

/**
     * Draw a {@link net.minecraft.util.ResourceLocation} on given coords with given scaling
     *
     * @param x        xPos
     * @param y        yPos
     * @param z        zPos
     * @param u        uPos on the {@link net.minecraft.util.ResourceLocation}
     * @param v        vPos on the {@link net.minecraft.util.ResourceLocation}
     * @param w        width
     * @param h        height
     * @param scale    the scale to draw 1.0F is exact, less is smaller and bigger is larger
     * @param resource the {@link net.minecraft.util.ResourceLocation}
     */
public static void drawScaledTexturedRectUV(float x, float y, float z, float u, float v, float w, float h, float scale, ResourceLocation resource) {
    Minecraft.getMinecraft().getTextureManager().bindTexture(resource);
    float drawH = h * scale;
    float drawW = w * scale;
    float xScale = 1.0F / w;
    float yScale = 1.0F / h;
    Tessellator tessellator = Tessellator.instance;
    tessellator.startDrawingQuads();
    tessellator.addVertexWithUV(x, y + drawH, z, u * xScale, (v + h) * yScale);
    tessellator.addVertexWithUV(x + drawW, y + drawH, z, (u + w) * xScale, (v + h) * yScale);
    tessellator.addVertexWithUV(x + drawW, y, z, (u + w) * xScale, v * yScale);
    tessellator.addVertexWithUV(x, y, z, u * xScale, v * yScale);
    tessellator.draw();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator)

Example 98 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project BetterStorage by copygirl.

the class RenderUtils method renderItemIn3d.

public static void renderItemIn3d(ItemStack stack) {
    TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
    // Not sure why but this can be null when the world loads.
    if (textureManager == null)
        return;
    Item item = stack.getItem();
    GL11.glPushMatrix();
    Tessellator tessellator = Tessellator.instance;
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glTranslatef(-0.5F, -0.5F, 1 / 32.0F);
    int passes = item.getRenderPasses(stack.getItemDamage());
    for (int pass = 0; pass < passes; pass++) {
        textureManager.bindTexture(((stack.getItemSpriteNumber() == 0) ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture));
        IIcon icon = item.getIcon(stack, pass);
        float minU = icon.getMinU();
        float maxU = icon.getMaxU();
        float minV = icon.getMinV();
        float maxV = icon.getMaxV();
        RenderUtils.setColorFromInt(item.getColorFromItemStack(stack, pass));
        ItemRenderer.renderItemIn2D(tessellator, maxU, minV, minU, maxV, icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
    }
    if (stack.hasEffect(0)) {
        GL11.glDepthFunc(GL11.GL_EQUAL);
        GL11.glDisable(GL11.GL_LIGHTING);
        textureManager.bindTexture(glint);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
        float f7 = 0.76F;
        GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F);
        GL11.glMatrixMode(GL11.GL_TEXTURE);
        GL11.glPushMatrix();
        float f8 = 0.125F;
        GL11.glScalef(f8, f8, f8);
        float f9 = Minecraft.getSystemTime() % 3000L / 3000.0F * 8.0F;
        GL11.glTranslatef(f9, 0.0F, 0.0F);
        GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
        ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
        GL11.glPopMatrix();
        GL11.glPushMatrix();
        GL11.glScalef(f8, f8, f8);
        f9 = Minecraft.getSystemTime() % 4873L / 4873.0F * 8.0F;
        GL11.glTranslatef(-f9, 0.0F, 0.0F);
        GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
        ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glDepthFunc(GL11.GL_LEQUAL);
    }
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glPopMatrix();
}
Also used : Item(net.minecraft.item.Item) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Tessellator(net.minecraft.client.renderer.Tessellator) IIcon(net.minecraft.util.IIcon)

Example 99 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project minecolonies by Minecolonies.

the class TextField method drawSelf.

/**
     * Draw itself at positions mx and my.
     */
@Override
protected void drawSelf(final int mx, final int my) {
    final int color = enabled ? textColor : textColorDisabled;
    final int drawWidth = getInternalWidth();
    final int drawX = x;
    final int drawY = y;
    //  Determine the portion of the string that is visible on screen
    final String visibleString = mc.fontRendererObj.trimStringToWidth(text.substring(scrollOffset), drawWidth);
    final int relativeCursorPosition = cursorPosition - scrollOffset;
    int relativeSelectionEnd = selectionEnd - scrollOffset;
    final boolean cursorVisible = relativeCursorPosition >= 0 && relativeCursorPosition <= visibleString.length();
    final boolean cursorBeforeEnd = cursorPosition < text.length() || text.length() >= maxTextLength;
    //  Enforce selection to the length limit of the visible string
    if (relativeSelectionEnd > visibleString.length()) {
        relativeSelectionEnd = visibleString.length();
    }
    //  Draw string up through cursor
    int textX = drawX;
    if (visibleString.length() > 0) {
        @NotNull final String s1 = cursorVisible ? visibleString.substring(0, relativeCursorPosition) : visibleString;
        mc.renderEngine.bindTexture(TEXTURE);
        textX = mc.fontRendererObj.drawString(s1, textX, drawY, color, shadow);
    }
    int cursorX = textX;
    if (!cursorVisible) {
        cursorX = relativeCursorPosition > 0 ? (drawX + width) : drawX;
    } else if (cursorBeforeEnd && shadow) {
        textX -= 1;
        cursorX -= 1;
    }
    //  Draw string after cursor
    if (visibleString.length() > 0 && cursorVisible && relativeCursorPosition < visibleString.length()) {
        mc.renderEngine.bindTexture(TEXTURE);
        mc.fontRendererObj.drawString(visibleString.substring(relativeCursorPosition), textX, drawY, color, shadow);
    }
    //  Should we draw the cursor this frame?
    if (isFocus() && cursorVisible && (cursorBlinkCounter / 6 % 2 == 0)) {
        if (cursorBeforeEnd) {
            drawRect(cursorX, drawY - 1, cursorX + 1, drawY + 1 + mc.fontRendererObj.FONT_HEIGHT, RECT_COLOR);
        } else {
            mc.renderEngine.bindTexture(TEXTURE);
            mc.fontRendererObj.drawString("_", cursorX, drawY, color, shadow);
        }
    }
    //  Draw selection
    if (relativeSelectionEnd != relativeCursorPosition) {
        final int selectedDrawX = drawX + mc.fontRendererObj.getStringWidth(visibleString.substring(0, relativeSelectionEnd));
        int selectionStartX = Math.min(cursorX, selectedDrawX - 1);
        int selectionEndX = Math.max(cursorX, selectedDrawX - 1);
        if (selectionStartX > (x + width)) {
            selectionStartX = x + width;
        }
        if (selectionEndX > (x + width)) {
            selectionEndX = x + width;
        }
        final Tessellator tessellator = Tessellator.getInstance();
        GlStateManager.color(0.0F, 0.0F, 255.0F, 255.0F);
        GlStateManager.disableTexture2D();
        GlStateManager.enableColorLogic();
        GlStateManager.colorLogicOp(GL11.GL_OR_REVERSE);
        final VertexBuffer vertexBuffer = tessellator.getBuffer();
        // There are several to choose from, look at DefaultVertexFormats for more info
        vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        //Since our points do not have any u,v this seems to be the correct code
        vertexBuffer.pos((double) selectionStartX, (double) drawY + 1 + mc.fontRendererObj.FONT_HEIGHT, 0.0D).endVertex();
        vertexBuffer.pos((double) selectionEndX, (double) drawY + 1 + mc.fontRendererObj.FONT_HEIGHT, 0.0D).endVertex();
        vertexBuffer.pos((double) selectionEndX, (double) drawY - 1, 0.0D).endVertex();
        vertexBuffer.pos((double) selectionStartX, (double) drawY - 1, 0.0D).endVertex();
        tessellator.draw();
        GlStateManager.disableColorLogic();
        GlStateManager.enableTexture2D();
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with Tessellator

use of net.minecraft.client.renderer.Tessellator in project ArsMagica2 by Mithion.

the class EssenceGeneratorRenderer method renderObelisk.

private void renderObelisk(TileEntityObelisk tile, double d, double d1, double d2, float f) {
    if (tile.xCoord == 0 && tile.yCoord == 0 && tile.zCoord == 0) {
        GL11.glScalef(0.75f, 0.75f, 0.75f);
        GL11.glTranslatef(0, -0.5f, 0);
    }
    int i = 2;
    if (tile.getWorldObj() != null) {
        i = tile.getBlockMetadata();
    }
    int j = i * 90;
    GL11.glTranslated(d + 0.5, d1, d2 + 0.5);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    Tessellator tessellator = Tessellator.instance;
    if (tile.isHighPowerActive())
        bindTexture(rLoc_obelisk_active_highpower);
    else if (tile.isActive())
        bindTexture(rLoc_obelisk_active);
    else
        bindTexture(rLoc_obelisk);
    //rotate based on metadata
    GL11.glRotatef(j, 0.0F, 1.0F, 0.0F);
    try {
        model_obelisk.renderAll();
    } catch (Throwable t) {
    }
    //runes
    if (tile.isActive()) {
        GL11.glMatrixMode(GL11.GL_TEXTURE);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        bindTexture(rLoc_obelisk_runes);
        float normx = (System.currentTimeMillis() % 32000) / 32000.0f;
        float normy = (System.currentTimeMillis() % 28000) / 28000.0f;
        GL11.glTranslatef(normx, normy, 0);
        float transp = (float) Math.abs(Math.sin(System.currentTimeMillis() / 1000.0));
        GL11.glColor4f(1, 1, 1, transp);
        try {
            model_obelisk.renderAll();
        } catch (Throwable t) {
        }
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator)

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