Example usage for org.lwjgl.opengl GL11 glPushAttrib

List of usage examples for org.lwjgl.opengl GL11 glPushAttrib

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glPushAttrib.

Prototype

public static native void glPushAttrib(@NativeType("GLbitfield") int mask);

Source Link

Document

Takes a bitwise OR of symbolic constants indicating which groups of state variables to push onto the server attribute stack.

Usage

From source file:mods.railcraft.client.render.carts.CartContentRendererTNT.java

License:Open Source License

@Override
public void render(RenderCart renderer, EntityMinecart cart, float light, float time) {
    GL11.glPushMatrix();// w  w w. j ava 2 s.  c om
    //        GL11.glTranslatef(0.0F, 0.3125F, 0.0F);
    //        GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
    CartExplosiveBase tnt = (CartExplosiveBase) cart;
    if (tnt.isPrimed() && ((float) tnt.getFuse() - time) + 1.0F < 10F) {
        float scale = 1.0F - (((float) tnt.getFuse() - time) + 1.0F) / 10F;
        if (scale < 0.0F) {
            scale = 0.0F;
        }
        if (scale > 1.0F) {
            scale = 1.0F;
        }
        scale *= scale;
        scale *= scale;
        scale = 1.0F + scale * 0.3F;
        GL11.glScalef(scale, scale, scale);
    }
    super.render(renderer, cart, light, time);
    if (tnt.isPrimed() && (tnt.getFuse() / 5) % 2 == 0) {
        GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(770, 772);
        float alpha = (1.0F - (((float) tnt.getFuse() - time) + 1.0F) / 100F) * 0.8F;
        GL11.glColor4f(1.0F, 1.0F, 1.0F, alpha);
        GL11.glScalef(1.01f, 1.01f, 1.01f);
        super.render(renderer, cart, 1, time);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glPopAttrib();
    }
    GL11.glPopMatrix();
}

From source file:mods.railcraft.client.render.carts.LocomotiveRendererDefault.java

License:Open Source License

@Override
public void renderLocomotive(IRenderer renderer, EntityMinecart cart, int primaryColor, int secondaryColor,
        ResourceLocation emblemTexture, float light, float time) {
    GL11.glPushMatrix();//  w ww. ja  v a2s .co m
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.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;
        GL11.glColor4f(c1 * dim, c2 * dim, c3 * dim, 1);
        model.render(cart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    }
    GL11.glPopAttrib();

    if (emblemTexture != null) {
        renderer.bindTex(emblemTexture);
        Tessellator tess = Tessellator.instance;

        //            float size = 0.22F;
        //            float offsetX = -0.25F;
        //            float offsetY = -0.25F;
        //            float offsetZ = -0.46F;
        tess.startDrawingQuads();
        tess.addVertexWithUV(emblemOffsetX - emblemSize, emblemOffsetY - emblemSize, emblemOffsetZ, 0, 0);
        tess.addVertexWithUV(emblemOffsetX - emblemSize, emblemOffsetY + emblemSize, emblemOffsetZ, 0, 1);
        tess.addVertexWithUV(emblemOffsetX + emblemSize, emblemOffsetY + emblemSize, emblemOffsetZ, 1, 1);
        tess.addVertexWithUV(emblemOffsetX + emblemSize, emblemOffsetY + -emblemSize, emblemOffsetZ, 1, 0);

        tess.addVertexWithUV(emblemOffsetX + emblemSize, emblemOffsetY + -emblemSize, -emblemOffsetZ, 0, 0);
        tess.addVertexWithUV(emblemOffsetX + emblemSize, emblemOffsetY + emblemSize, -emblemOffsetZ, 0, 1);
        tess.addVertexWithUV(emblemOffsetX - emblemSize, emblemOffsetY + emblemSize, -emblemOffsetZ, 1, 1);
        tess.addVertexWithUV(emblemOffsetX - emblemSize, emblemOffsetY - emblemSize, -emblemOffsetZ, 1, 0);
        tess.draw();
    }
    GL11.glPopMatrix();
}

From source file:mods.railcraft.client.render.carts.LocomotiveRendererElectric.java

License:Open Source License

@Override
public void renderLocomotive(IRenderer renderer, EntityMinecart cart, int primaryColor, int secondaryColor,
        ResourceLocation emblemTexture, float light, float time) {
    super.renderLocomotive(renderer, cart, primaryColor, secondaryColor, emblemTexture, light, time);
    GL11.glPushMatrix();/*w w w . j a  va2  s  .co m*/
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glScalef(-1F, -1F, 1.0F);
    GL11.glTranslatef(0.05F, 0.0F, 0.0F);

    if (((EntityLocomotive) cart).getMode() == EntityLocomotive.LocoMode.RUNNING) {
        renderer.bindTex(LAMP_TEX_ON);
        LAMP_ON.render(cart, -0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    } else {
        renderer.bindTex(LAMP_TEX_OFF);
        LAMP_OFF.render(cart, -0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    }

    GL11.glPopAttrib();
    GL11.glPopMatrix();
}

From source file:mods.railcraft.client.render.carts.RenderCart.java

License:Open Source License

public void renderCart(EntityMinecart cart, double x, double y, double z, float yaw, float time) {
    GL11.glPushMatrix();//from   w  ww . ja  va 2s .  c o m
    long var10 = (long) cart.getEntityId() * 493286711L;
    var10 = var10 * var10 * 4392167121L + var10 * 98761L;
    float tx = (((float) (var10 >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    float ty = (((float) (var10 >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    float tz = (((float) (var10 >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    GL11.glTranslatef(tx, ty, tz);
    double mx = cart.lastTickPosX + (cart.posX - cart.lastTickPosX) * (double) time;
    double my = cart.lastTickPosY + (cart.posY - cart.lastTickPosY) * (double) time;
    double mz = cart.lastTickPosZ + (cart.posZ - cart.lastTickPosZ) * (double) time;
    double d6 = 0.3;
    Vec3 vec3d = cart.func_70489_a(mx, my, mz);
    float pitch = cart.prevRotationPitch + (cart.rotationPitch - cart.prevRotationPitch) * time;
    if (vec3d != null) {
        Vec3 vec3d1 = cart.func_70495_a(mx, my, mz, d6);
        Vec3 vec3d2 = cart.func_70495_a(mx, my, mz, -d6);
        if (vec3d1 == null)
            vec3d1 = vec3d;
        if (vec3d2 == null)
            vec3d2 = vec3d;
        x += vec3d.xCoord - mx;
        y += (vec3d1.yCoord + vec3d2.yCoord) / 2D - my;
        z += vec3d.zCoord - mz;
        Vec3 vec3d3 = vec3d2.addVector(-vec3d1.xCoord, -vec3d1.yCoord, -vec3d1.zCoord);
        if (vec3d3.lengthVector() != 0.0D) {
            vec3d3 = vec3d3.normalize();
            yaw = (float) (Math.atan2(vec3d3.zCoord, vec3d3.xCoord) / Math.PI) * 180;
            pitch = (float) (Math.atan(vec3d3.yCoord) * 73D);
        }
    }
    if (cart instanceof IDirectionalCart) {
        yaw %= 360;
        if (yaw < 0)
            yaw += 360;
        yaw += 360;

        double serverYaw = cart.rotationYaw;
        serverYaw += 180;
        serverYaw %= 360;
        if (serverYaw < 0)
            serverYaw += 360;
        serverYaw += 360;

        if (Math.abs(yaw - serverYaw) > 90) {
            yaw += 180;
            pitch = -pitch;
        }

        ((IDirectionalCart) cart).setRenderYaw(yaw);
    }
    GL11.glTranslatef((float) x, (float) y, (float) z);

    boolean name = false;
    if (cart.hasCustomInventoryName()) {
        renderHaloText(cart, cart.getCommandSenderName(), 0, 0, 0, 64);
        name = true;
    }

    if (cart instanceof IRoutableCart) {
        String dest = ((IRoutableCart) cart).getDestination();
        if (!dest.isEmpty())
            renderHaloText(cart, dest, 0, name ? 0.5 : 0, 0, 64);
    }

    GL11.glRotatef(180F - yaw, 0.0F, 1.0F, 0.0F);
    GL11.glRotatef(-pitch, 0.0F, 0.0F, 1.0F);

    float f3 = (float) cart.getRollingAmplitude() - time;
    float f4 = (float) cart.getDamage() - time;
    if (f4 < 0.0F)
        f4 = 0.0F;
    if (f3 > 0.0F) {
        float angle = (MathHelper.sin(f3) * f3 * f4) / 10F;
        angle = Math.min(angle, 0.8f);
        angle = Math.copySign(angle, cart.getRollingDirection());
        GL11.glRotatef(angle, 1.0F, 0.0F, 0.0F);
    }
    float light = cart.getBrightness(time);
    //        light = light + ((1.0f - light) * 0.4f);

    boolean renderContents = renderCore(cart, light, time);

    if (renderContents) {
        float blockScale = 0.74F;
        GL11.glScalef(blockScale, blockScale, blockScale);
        GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
        renderContents(cart, light, time);
        GL11.glPopAttrib();
    }
    GL11.glPopMatrix();
}

From source file:mods.railcraft.client.render.carts.RenderCartItemFiltered.java

License:Open Source License

@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
    GL11.glPushMatrix();/*from www.j  a  va2 s .  c o m*/
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    IIcon cartTexture = stack.getIconIndex();
    renderItem.renderIcon(0, 0, cartTexture, 16, 16);

    ItemStack filter = EntityCartFiltered.getFilterFromCartItem(stack);
    if (filter != null) {
        rendererType.setupRender();
        RenderItem.getInstance().renderItemAndEffectIntoGUI(Minecraft.getMinecraft().fontRenderer,
                Minecraft.getMinecraft().getTextureManager(), filter, 0, 0);
    }

    GL11.glPopAttrib();
    GL11.glPopMatrix();
}

From source file:mods.railcraft.client.render.carts.RenderItemLocomotive.java

License:Open Source License

private void render(ItemStack stack, float scale) {
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);/*from  ww w.  j a  v  a  2 s .c  o  m*/
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glScalef(scale, scale, scale);

    entity.rotationYaw = 0;
    entity.rotationPitch = 0;
    entity.setModel(ItemLocomotive.getModel(stack));
    entity.setPrimaryColor(ItemLocomotive.getPrimaryColor(stack).ordinal());
    entity.setSecondaryColor(ItemLocomotive.getSecondaryColor(stack).ordinal());

    LocomotiveRenderer.INSTANCE.render(this, entity, 1.0F, 1.0F);

    GL11.glPopAttrib();
}

From source file:mods.railcraft.client.render.carts.RenderTunnelBore.java

License:Open Source License

public void render(EntityTunnelBore bore, double x, double y, double z, float yaw, float time) {
    // System.out.println("Render Yaw = " + f);
    GL11.glPushMatrix();/*from   ww w .  j a v a  2s . c o  m*/
    long var10 = (long) bore.getEntityId() * 493286711L;
    var10 = var10 * var10 * 4392167121L + var10 * 98761L;
    float tx = (((float) (var10 >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    float ty = (((float) (var10 >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    float tz = (((float) (var10 >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    GL11.glTranslatef(tx, ty, tz);

    if (RenderManager.debugBoundingBox) {
        GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
        //            GL11.glDepthMask(false);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_BLEND);
        for (Entity part : bore.getParts()) {
            GL11.glPushMatrix();
            double posX = part.lastTickPosX + (part.posX - part.lastTickPosX) * (double) time
                    - RenderManager.renderPosX;
            double posY = part.lastTickPosY + (part.posY - part.lastTickPosY) * (double) time
                    - RenderManager.renderPosY;
            double posZ = part.lastTickPosZ + (part.posZ - part.lastTickPosZ) * (double) time
                    - RenderManager.renderPosZ;
            GL11.glTranslatef((float) posX, (float) posY, (float) posZ);
            float halfWidth = part.width / 2.0F;
            AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(-halfWidth, 0.0, -halfWidth, halfWidth,
                    part.height, halfWidth);
            RenderGlobal.drawOutlinedBoundingBox(axisalignedbb, 16777215);
            GL11.glPopMatrix();
        }
        //            GL11.glDepthMask(true);
        GL11.glPopAttrib();
    }

    GL11.glTranslatef((float) x, (float) y, (float) z);
    switch (bore.getFacing()) {
    case NORTH:
        yaw = 90;
        break;
    case EAST:
        yaw = 0;
        break;
    case SOUTH:
        yaw = 270;
        break;
    case WEST:
        yaw = 180;
        break;
    }
    GL11.glRotatef(yaw, 0.0F, 1.0F, 0.0F);
    float f3 = (float) bore.getRollingAmplitude() - time;
    float f4 = (float) bore.getDamage() - time;
    if (f4 < 0.0F) {
        f4 = 0.0F;
    }
    if (f3 > 0.0F) {
        float angle = (MathHelper.sin(f3) * f3 * f4) / 10F;
        angle = Math.min(angle, 0.8f);
        angle = Math.copySign(angle, bore.getRollingDirection());
        GL11.glRotatef(angle, 1.0F, 0.0F, 0.0F);
    }
    float light = bore.getBrightness(time);
    light = light + ((1.0f - light) * 0.4f);

    int j = 0xffffff;
    float c1 = (float) (j >> 16 & 0xff) / 255F;
    float c2 = (float) (j >> 8 & 0xff) / 255F;
    float c3 = (float) (j & 0xff) / 255F;

    GL11.glColor4f(c1 * light, c2 * light, c3 * light, 1.0F);

    IBoreHead head = bore.getBoreHead();
    if (head != null) {
        bindTexture(head.getBoreTexture());
        modelTunnelBore.setRenderBoreHead(true);
    } else {
        bindTexture(TEXTURE);
        modelTunnelBore.setRenderBoreHead(false);
    }

    GL11.glScalef(-1F, -1F, 1.0F);

    modelTunnelBore.setBoreHeadRotation(bore.getBoreRotationAngle());
    modelTunnelBore.setBoreActive(bore.isMinecartPowered());
    modelTunnelBore.render(0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    GL11.glPopMatrix();
}

From source file:mods.railcraft.client.render.RenderBlockFrame.java

License:Open Source License

@Override
public void renderItem(RenderBlocks renderBlocks, ItemStack item, ItemRenderType renderType) {
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);/*from  www .jav  a 2s  . c  o  m*/
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    BlockFrame.flipTextures = true;
    getBlock().setBlockBounds(1, 1, 1, 0, 0, 0);
    RenderTools.renderBlockOnInventory(renderBlocks, getBlock(), item.getItemDamage(), 1);
    BlockFrame.flipTextures = false;
    getBlock().setBlockBounds(0, 0, 0, 1, 1, 1);
    RenderTools.renderBlockOnInventory(renderBlocks, getBlock(), item.getItemDamage(), 1);

    GL11.glPopAttrib();
}

From source file:mods.railcraft.client.render.RenderBlockOre.java

License:Open Source License

@Override
public void renderItem(RenderBlocks renderBlocks, ItemStack item, ItemRenderType renderType) {
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);// w  w  w  .j a v  a 2s  .c o  m
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    BlockOre.renderPass = 0;
    renderItem(renderBlocks, item, getBlock().getIcon(0, item.getItemDamage()));
    BlockOre.renderPass = 1;
    renderItem(renderBlocks, item, getBlock().getIcon(0, item.getItemDamage()));

    GL11.glPopAttrib();

}

From source file:mods.railcraft.client.render.RenderChest.java

License:Open Source License

/**
 * Helps to render Ender Chest.//from   w  w  w . jav  a2s  .c  o m
 */
public void renderChest(TileChestRailcraft tile, double x, double y, double z, float time) {
    int facing = tile.getFacing().ordinal();

    bindTexture(texture);
    GL11.glPushMatrix();
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
    GL11.glScalef(1.0F, -1.0F, -1.0F);
    GL11.glTranslatef(0.5F, 0.5F, 0.5F);
    short rotation = 0;

    switch (facing) {
    case 2:
        rotation = 180;
        break;
    case 3:
        rotation = 0;
        break;
    case 4:
        rotation = 90;
        break;
    case 5:
        rotation = -90;
        break;
    }

    GL11.glRotatef((float) rotation, 0.0F, 1.0F, 0.0F);
    GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
    float lidAngle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * time;
    lidAngle = 1.0F - lidAngle;
    lidAngle = 1.0F - lidAngle * lidAngle * lidAngle;
    this.chestModel.chestLid.rotateAngleX = -(lidAngle * (float) Math.PI / 2.0F);
    this.chestModel.renderAll();
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glPopAttrib();
    GL11.glPopMatrix();
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}