Example usage for org.lwjgl.opengl GL11 GL_MODELVIEW

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

Introduction

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

Prototype

int GL_MODELVIEW

To view the source code for org.lwjgl.opengl GL11 GL_MODELVIEW.

Click Source Link

Document

MatrixMode

Usage

From source file:$.DrawSystem.java

License:Open Source License

@Override
    protected void processEntities(ImmutableBag<Entity> entities) {
        GL11.glClearColor(0.1f, 0, 0, 1f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        List<Entity> entititesSortedByZ = new ArrayList<>(entities.size());
        for (int i = 0, n = entities.size(); i < n; ++i) {
            final Entity e = entities.get(i);
            if (e.isEnabled()) {
                entititesSortedByZ.add(e);
            }/*from  ww  w. j av a2 s. c o m*/
        }
        Collections.sort(entititesSortedByZ, zComparator);

        GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_TRANSFORM_BIT | GL11.GL_HINT_BIT | GL11.GL_COLOR_BUFFER_BIT
                | GL11.GL_SCISSOR_BIT | GL11.GL_LINE_BIT | GL11.GL_TEXTURE_BIT);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();

        updateViewPort();
        GL11.glViewport(viewPort.x, viewPort.y, viewPort.width, viewPort.height);
        GLU.gluOrtho2D(-toolkit.getVirtualResolutionWidth() / 2.0f, toolkit.getVirtualResolutionWidth() / 2.0f,
                toolkit.getVirtualResolutionHeight() / 2.0f, -toolkit.getVirtualResolutionHeight() / 2.0f);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);

        Game game = (Game) world;
        Entity hero = game.getHero();
        if (null != hero) {
            Sprite heroSprite = spriteMapper.get(hero);
            Vector heroPos = spriteProjector.project(heroSprite.getPosition());
            GL11.glTranslatef(-heroPos.x, -heroPos.y, 0.0f);
        }

        for (Entity e : entititesSortedByZ) {
            MainMenu mainMenu = mainMenuMapper.getSafe(e);
            if (null != mainMenu) {
                mainMenu.draw();
            }
            DialogueComponent dialog = dialogMapper.getSafe(e);
            if (null != dialog) {
                dialog.draw();
            }
            Level level = levelMapper.getSafe(e);
            if (null != level) {
                drawLevel(level);
            }
            Sprite sprite = spriteMapper.getSafe(e);
            if (null != sprite) {
                drawSprite(sprite);
            }
        }
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPopMatrix();
        GL11.glPopAttrib();

    }

From source file:a1.Main.java

License:Open Source License

private void setView(int screenWidth, int screenHeight) {
    GL11.glViewport(0, 0, screenWidth, screenHeight);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();/*from  w  w w  .  j  a v  a 2  s .  c o  m*/
    GL11.glOrtho(0, screenWidth, screenHeight, 0, -1, 1);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
}

From source file:advancedbrewing.renderer.ItemGlintOverlayRenderer.java

License:Minecraft Mod Public

private void renderItem3D(ItemRenderType type, ItemStack itemStack, Object... data) {
    TextureManager renderEngine = FMLClientHandler.instance().getClient().renderEngine;
    Tessellator tessellator = Tessellator.instance;

    if (this.shouldRenderOverlay(itemStack)) {
        // render colored overlay
        renderEngine.bindTexture(renderEngine.getResourceLocation(itemStack.getItemSpriteNumber()));
        this.setColorByItemStack(itemStack);
        Icon icon = this.getIcon(itemStack, 0);
        ItemRenderer.renderItemIn2D(tessellator, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(),
                icon.getIconWidth(), icon.getIconHeight(), 0.0625F);

        // render glint
        if (itemStack.hasEffect(0)) {
            renderEngine.bindTexture(ItemGlintOverlayRenderer.RES_ITEM_GLINT);

            GL11.glDepthFunc(GL11.GL_EQUAL);
            GL11.glDisable(GL11.GL_LIGHTING);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glMatrixMode(GL11.GL_TEXTURE);

            GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
            GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F);

            // first pass
            GL11.glPushMatrix();//  w  ww .j a  va 2s.  c o m
            GL11.glScalef(0.125F, 0.125F, 0.125F);
            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();

            // second pass
            GL11.glPushMatrix();
            GL11.glScalef(0.125F, 0.125F, 0.125F);
            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);
        }
    }

    // render uncolored icon
    renderEngine.bindTexture(renderEngine.getResourceLocation(itemStack.getItemSpriteNumber()));
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    Icon icon = this.getIcon(itemStack, 1);
    ItemRenderer.renderItemIn2D(tessellator, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(),
            icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
}

From source file:akarnokd.opengl.experiment.FontExample.java

License:Apache License

/**
 * Initialise the GL display//  w w w  .  j a  v a 2  s  .c  o m
 * 
 * @param width The width of the display
 * @param height The height of the display
 */
private void initGL(int width, int height) {
    try {
        Display.setDisplayMode(new DisplayMode(width, height));
        Display.create();
        Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glClearDepth(1);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glViewport(0, 0, width, height);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, height, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

From source file:aphelion.client.Client.java

License:Open Source License

public static void initGL() {
    int displayWidth = Display.getWidth();
    int displayHeight = Display.getHeight();

    glDisableAll();/*from   www. ja v a2  s .  c  o m*/

    GL11.glViewport(0, 0, displayWidth, displayHeight);

    GL11.glMatrixMode(GL11.GL_PROJECTION); // Apply subsequent matrix operations to the projection matrix stack.
    GL11.glLoadIdentity();
    GL11.glOrtho(0, displayWidth, displayHeight, 0, -1, 1);

    GL11.glMatrixMode(GL11.GL_TEXTURE);
    GL11.glLoadIdentity();

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
    AsyncTexture.unbind();

    // Enable alpha channels for images
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);

    Graph.g.setDimensions(displayWidth, displayHeight);
    Graphics.setCurrent(Graph.g);
    Graph.g.setDrawMode(Graphics.MODE_NORMAL);
}

From source file:arg.RenderRecipe.java

License:Open Source License

public void draw() {

    File dir = new File(Minecraft.getMinecraft().mcDataDir, "recipes");
    if (!dir.exists() && !dir.mkdirs()) {
        throw new RuntimeException("The recipes directory could not be created: " + dir);
    }/*from www. j av  a 2 s .c  o m*/

    name = name.replace(" ", "");
    File file = new File(Minecraft.getMinecraft().mcDataDir, "recipes/" + name + ".png");

    if (file.exists())
        return;

    GL11.glPushMatrix();
    GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
    GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glViewport(0, 0, width, height);
    GL11.glOrtho(0.0D, xSize, ySize, 0.0D, 1000.0D, 3000.0D);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
    GL11.glLineWidth(1.0F);

    GL11.glEnable(GL11.GL_COLOR_MATERIAL);

    try {
        drawScreen(0, 0, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }

    int[] pixels = new int[width * height];
    int bindex;

    ByteBuffer fb = ByteBuffer.allocateDirect(width * height * 3);

    GL11.glReadPixels(0, 0, width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, fb);
    GL11.glPopMatrix();
    GL11.glPopAttrib();
    GL11.glPopClientAttrib();
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    try {
        Display.swapBuffers();
    } catch (LWJGLException e1) {
        e1.printStackTrace();
    }

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            int i = (x + (width * y)) * 3;
            int r = fb.get(i) & 0xFF;
            int g = fb.get(i + 1) & 0xFF;
            int b = fb.get(i + 2) & 0xFF;
            image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
        }
    }

    try {
        ImageIO.write(image, "png", file);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:br.org.archimedes.gui.opengl.OpenGLWrapper.java

License:Open Source License

/**
 * Clears the OpenGL canvas.//from  w  w w . j ava2s. c o m
 */
public void clear() {
    Color currentBkColor = br.org.archimedes.Utils.getWorkspace().getBackgroundColor();
    GL11.glClearColor((float) currentBkColor.getR(), (float) currentBkColor.getG(),
            (float) currentBkColor.getB(), 0);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    resize();
}

From source file:buildcraft.robotics.gui.GuiZonePlanner.java

License:Mozilla Public License

@SuppressWarnings("PointlessBitwiseExpression")
@Override/* ww w.  j  a  v a2  s . c  o  m*/
protected void drawForegroundLayer() {
    camY += scaleSpeed;
    scaleSpeed *= 0.7F;
    int posX = (int) positionX;
    int posZ = (int) positionZ;
    int dimension = Minecraft.getMinecraft().world.provider.getDimension();
    {
        ChunkPos chunkPos = new ChunkPos(posX >> 4, posZ >> 4);
        ZonePlannerMapChunkKey key = new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel());
        ZonePlannerMapChunk chunk = ZonePlannerMapDataClient.INSTANCE.getLoadedChunk(key);
        BlockPos pos = null;
        if (chunk != null) {
            MapColourData data = chunk.getData(posX, posZ);
            if (data != null) {
                pos = new BlockPos(posX, data.posY, posZ);
            }
        }
        if (pos != null && pos.getY() + 10 > camY) {
            camY = Math.max(camY, pos.getY() + 10);
        }
    }
    int x = guiLeft;
    int y = guiTop;
    if (lastSelected != null) {
        String text = "X: " + lastSelected.getX() + " Y: " + lastSelected.getY() + " Z: " + lastSelected.getZ();
        fontRendererObj.drawString(text, x + 130, y + 130, 0x404040);
    }
    int offsetX = 8;
    int offsetY = 9;
    int sizeX = 213;
    int sizeY = 100;
    GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT); // TODO: save depth buffer?
    GlStateManager.pushMatrix();
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.pushMatrix();
    GlStateManager.loadIdentity();
    ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
    GlStateManager.viewport(//
            (x + offsetX) * scaledResolution.getScaleFactor(), //
            Minecraft.getMinecraft().displayHeight - (sizeY + y + offsetY) * scaledResolution.getScaleFactor(), //
            sizeX * scaledResolution.getScaleFactor(), //
            sizeY * scaledResolution.getScaleFactor()//
    );
    GlStateManager.scale(scaledResolution.getScaleFactor(), scaledResolution.getScaleFactor(), 1);
    GLU.gluPerspective(70.0F, (float) sizeX / sizeY, 1F, 1000.0F);
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.loadIdentity();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.enableRescaleNormal();
    GlStateManager.rotate(90, 1, 0, 0); // look down
    GlStateManager.pushMatrix();
    GlStateManager.translate(-positionX, -camY, -positionZ);
    GlStateManager.disableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.disableTexture2D();
    int chunkBaseX = posX >> 4;
    int chunkBaseZ = posZ >> 4;
    int radius = 8;
    for (int chunkX = chunkBaseX - radius; chunkX < chunkBaseX + radius; chunkX++) {
        for (int chunkZ = chunkBaseZ - radius; chunkZ < chunkBaseZ + radius; chunkZ++) {
            ZonePlannerMapChunkKey key = new ZonePlannerMapChunkKey(new ChunkPos(chunkX, chunkZ), dimension,
                    container.tile.getLevel());
            int glId = ZonePlannerMapRenderer.INSTANCE.getChunkGlList(key);
            if (glId > 0) {
                GlStateManager.callList(glId);
            }
        }
    }

    BlockPos found = null;
    int foundColor = 0;

    if (Mouse.getX() / scaledResolution.getScaleFactor() > x + offsetX
            && Mouse.getX() / scaledResolution.getScaleFactor() < x + offsetX + sizeX
            && scaledResolution.getScaledHeight() - Mouse.getY() / scaledResolution.getScaleFactor() > y
                    + offsetY
            && scaledResolution.getScaledHeight() - Mouse.getY() / scaledResolution.getScaleFactor() < y
                    + offsetY + sizeY) {
        FloatBuffer projectionBuffer = BufferUtils.createFloatBuffer(16);
        FloatBuffer modelViewBuffer = BufferUtils.createFloatBuffer(16);
        IntBuffer viewportBuffer = BufferUtils.createIntBuffer(16);

        GlStateManager.getFloat(GL11.GL_PROJECTION_MATRIX, projectionBuffer);
        GlStateManager.getFloat(GL11.GL_MODELVIEW_MATRIX, modelViewBuffer);
        GlStateManager.glGetInteger(GL11.GL_VIEWPORT, viewportBuffer);

        FloatBuffer positionNearBuffer = BufferUtils.createFloatBuffer(3);
        FloatBuffer positionFarBuffer = BufferUtils.createFloatBuffer(3);

        GLU.gluUnProject(Mouse.getX(), Mouse.getY(), 0f, modelViewBuffer, projectionBuffer, viewportBuffer,
                positionNearBuffer);
        GLU.gluUnProject(Mouse.getX(), Mouse.getY(), 1f, modelViewBuffer, projectionBuffer, viewportBuffer,
                positionFarBuffer);

        Vector3d rayStart = new Vector3d(positionNearBuffer.get(0), positionNearBuffer.get(1),
                positionNearBuffer.get(2));
        Vector3d rayPosition = new Vector3d(rayStart);
        Vector3d rayDirection = new Vector3d(positionFarBuffer.get(0), positionFarBuffer.get(1),
                positionFarBuffer.get(2));
        rayDirection.sub(rayStart);
        rayDirection.normalize();
        Vector3d offset = new Vector3d(rayDirection);
        offset.scale(100);
        rayPosition.add(offset);
        rayDirection.negate();

        for (int i = 0; i < 100; i++) {
            int chunkX = (int) Math.round(rayPosition.getX()) >> 4;
            int chunkZ = (int) Math.round(rayPosition.getZ()) >> 4;
            ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE
                    .getLoadedChunk(new ZonePlannerMapChunkKey(new ChunkPos(chunkX, chunkZ),
                            Minecraft.getMinecraft().world.provider.getDimension(), container.tile.getLevel()));
            if (zonePlannerMapChunk != null) {
                BlockPos pos = new BlockPos(Math.round(rayPosition.getX()) - chunkX * 16,
                        Math.round(rayPosition.getY()), Math.round(rayPosition.getZ()) - chunkZ * 16);
                MapColourData data = zonePlannerMapChunk.getData(pos.getX(), pos.getZ());
                if (data != null && data.posY >= pos.getY()) {
                    found = new BlockPos(pos.getX() + chunkX * 16, data.posY, pos.getZ() + chunkZ * 16);
                    foundColor = data.colour;
                }
            } else {
                break;
            }
            rayPosition.add(rayDirection);
        }
    }

    if (found != null) {
        GlStateManager.disableDepth();
        GlStateManager.enableBlend();
        GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
        GlStateManager.glLineWidth(2);
        int r = (int) (((foundColor >> 16) & 0xFF) * 0.7);
        int g = (int) (((foundColor >> 8) & 0xFF) * 0.7);
        int b = (int) (((foundColor >> 0) & 0xFF) * 0.7);
        int a = 0x77;
        ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
        VertexBuffer builder = Tessellator.getInstance().getBuffer();
        builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
        ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(builder, found.getX(), found.getY(), found.getZ());
        Tessellator.getInstance().draw();
        GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
        GlStateManager.disableBlend();
        GlStateManager.enableDepth();
    }

    GlStateManager.disableLighting();
    GlStateManager.enableBlend();

    for (int i = 0; i < container.tile.layers.length; i++) {
        if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() != i) {
            continue;
        }
        ZonePlan layer = container.tile.layers[i];
        if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() == i
                && bufferLayer != null) {
            layer = bufferLayer;
        }
        if (!layer.getChunkPoses().isEmpty()) {
            for (int chunkX = chunkBaseX - radius; chunkX < chunkBaseX + radius; chunkX++) {
                for (int chunkZ = chunkBaseZ - radius; chunkZ < chunkBaseZ + radius; chunkZ++) {
                    ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ);
                    if (layer.hasChunk(chunkPos)) {
                        for (int blockX = chunkPos.getXStart(); blockX <= chunkPos.getXEnd(); blockX++) {
                            for (int blockZ = chunkPos.getZStart(); blockZ <= chunkPos.getZEnd(); blockZ++) {
                                if (layer.get(blockX, blockZ)) {
                                    int height = 256;
                                    ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE
                                            .getLoadedChunk(new ZonePlannerMapChunkKey(chunkPos, dimension,
                                                    container.tile.getLevel()));
                                    if (zonePlannerMapChunk != null) {
                                        MapColourData data = zonePlannerMapChunk.getData(blockX, blockZ);
                                        if (data != null) {
                                            height = data.posY;
                                        }
                                    }
                                    int color = EnumDyeColor.byMetadata(i).getMapColor().colorValue;
                                    int r = (color >> 16) & 0xFF;
                                    int g = (color >> 8) & 0xFF;
                                    int b = (color >> 0) & 0xFF;
                                    int a = 0x55;
                                    ZonePlannerMapRenderer.INSTANCE
                                            .setColor(r << 16 | g << 8 | b << 0 | a << 24);
                                    VertexBuffer builder = Tessellator.getInstance().getBuffer();
                                    builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
                                    ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(builder, blockX,
                                            height + 0.1, blockZ, height, 0.6);
                                    Tessellator.getInstance().draw();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    GlStateManager.disableBlend();
    GlStateManager.disableLighting();
    GlStateManager.enableTexture2D();

    lastSelected = found;
    GlStateManager.popMatrix();
    GlStateManager.disableRescaleNormal();
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.viewport(0, 0, Minecraft.getMinecraft().displayWidth,
            Minecraft.getMinecraft().displayHeight);
    GlStateManager.popMatrix();
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.popMatrix();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.disableBlend();
}

From source file:ccm.placeableTools.client.ToolRenderer.java

License:Open Source License

public static void doRenderPass(int i, int meta, ItemStack stack, double x, double y, double z) {
    Icon icon = stack.getItem().getIcon(stack, i);

    if (icon == null)
        return;//from  w  w w.  ja va  2s  .c om

    GL11.glPushMatrix();
    TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
    texturemanager.bindTexture(texturemanager.getResourceLocation(stack.getItemSpriteNumber()));
    Tessellator tessellator = Tessellator.instance;

    GL11.glTranslated(x, y, z); //Center to block
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);

    GL11.glTranslatef(-0.5f, .5f, 0.5f); // Center on block

    if (stack.getItem() instanceof ItemSpade || stack.getItem() instanceof ItemHoe) {
        float shift = 0.3f;
        switch (ForgeDirection.values()[meta]) {
        case NORTH:
            GL11.glTranslatef(0, 0, -shift);
            GL11.glRotatef(15f, -0.5f, 0, 0);
            break;
        case SOUTH:
            GL11.glTranslatef(0, 0, shift);
            GL11.glRotatef(-15f, -0.5f, 0, 0);
            break;
        case EAST:
            GL11.glRotatef(90f, 0, 1, 0);
            GL11.glTranslatef(-1, 0, 1);
            GL11.glTranslatef(0, 0, shift);
            GL11.glRotatef(-15f, -0.5f, 0, 0);
            break;
        case WEST:
            GL11.glRotatef(90f, 0, 1, 0);
            GL11.glTranslatef(-1, 0, 1);
            GL11.glTranslatef(0, 0, -shift);
            GL11.glRotatef(15f, -0.5f, 0, 0);
            break;
        case DOWN:
            GL11.glRotatef(90f, 0, 1, 0);
            GL11.glTranslatef(-1, 0, 1);
            break;
        }
        GL11.glTranslatef(0, 0, -0.03f); //Icon depth of the shovel
        GL11.glRotatef(180f, 1, 0, 0);
    } else if (stack.getItem() instanceof ItemAxe || stack.getItem() instanceof ItemPickaxe) {
        float shift = 0.15f;
        switch (ForgeDirection.values()[meta]) {
        case NORTH:
            GL11.glRotatef(90f, 0, 1, 0);
            GL11.glTranslatef(-1, 0, 1);
            GL11.glTranslatef(shift, 0, 0);
            GL11.glRotatef(-10f, 0, 0, 1);
            break;
        case SOUTH:
            GL11.glRotatef(-90f, 0, 1, 0);
            GL11.glTranslatef(-1, 0, -1);
            GL11.glTranslatef(shift, 0, 0);
            GL11.glRotatef(-10f, 0, 0, 1);
            break;
        case EAST:
            GL11.glTranslatef(shift, 0, 0);
            GL11.glRotatef(-10f, 0, 0, 1);
            break;
        case WEST:
            GL11.glRotatef(180f, 0, 1, 0);
            GL11.glTranslatef(-2, 0, 0);
            GL11.glTranslatef(shift, 0, 0);
            GL11.glRotatef(-10f, 0, 0, 1);
            break;
        }
        GL11.glTranslatef(0, 0, 0.03F);
    } else if (stack.getItem() instanceof ItemSword) {
        float shift = 0.15f;
        switch (ForgeDirection.values()[meta]) {
        case NORTH:
            GL11.glRotatef(90f, 0, 1, 0);
            GL11.glTranslatef(shift, 0, 0);
            GL11.glRotatef(-90f, 0, 0, 1);
            GL11.glTranslatef(-1, 0, 1);
            break;
        case SOUTH:
            GL11.glRotatef(-90f, 0, 1, 0);
            GL11.glTranslatef(shift, 0, 0);
            GL11.glRotatef(-90f, 0, 0, 1);
            GL11.glTranslatef(-1, 0, -1);
            break;
        case EAST:
            GL11.glTranslatef(shift, 0, 0);
            GL11.glRotatef(-90f, 0, 0, 1);
            GL11.glTranslatef(-1, 1, 0);
            break;
        case WEST:
            GL11.glRotatef(180f, 0, 1, 0);
            GL11.glTranslatef(-1, 1, 0);
            GL11.glTranslatef(shift, 0, 0);
            GL11.glRotatef(-90f, 0, 0, 1);
            break;
        case UP:
            GL11.glRotatef(180f, 1, 0, 0);
            GL11.glTranslatef(1, 0, 1);
            GL11.glRotatef(90f, 0, 1, 0);
            break;
        case DOWN:
            GL11.glRotatef(180f, 1, 0, 0);
            break;
        }
        GL11.glTranslatef(-0.05f, 0, 0.03F);
    }
    GL11.glRotatef(-45f, 0, 0, 1);
    GL11.glScalef(1.5f, 1.5f, 1.5f);
    ItemRenderer.renderItemIn2D(tessellator, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(),
            icon.getIconWidth(), icon.getIconHeight(), 0.06F / 1.5f);

    if (stack.hasEffect(i)) {
        GL11.glDepthFunc(GL11.GL_EQUAL);
        GL11.glDisable(GL11.GL_LIGHTING);
        texturemanager.bindTexture(RES_ITEM_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 = (float) (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.06F / 1.5f);
        GL11.glPopMatrix();
        GL11.glPushMatrix();
        GL11.glScalef(f8, f8, f8);
        f9 = (float) (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.06F / 1.5f);
        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();
}

From source file:cellularautomata.CellularAutomata.java

public static void renderGL() {
    try { //Trys to create a game window size 500x700.
        Display.setDisplayMode(new org.lwjgl.opengl.DisplayMode(800, 600));
        Display.create();//from   w  ww.  j a va  2s  .co m
    } catch (LWJGLException e) { //Catches exception if game window is not created.
        e.printStackTrace();
        System.exit(0);
    }

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Sets colour to white.
    GL11.glClearDepth(1);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glViewport(0, 0, 800, 600);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 800, 600, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    Display.setVSyncEnabled(vsync);
}