Example usage for org.lwjgl.opengl GL11 glTranslatef

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

Introduction

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

Prototype

public static native void glTranslatef(@NativeType("GLfloat") float x, @NativeType("GLfloat") float y,
        @NativeType("GLfloat") float z);

Source Link

Document

Manipulates the current matrix with a translation matrix along the x-, y- and z- axes.

Usage

From source file:com.github.begla.blockmania.world.chunk.Chunk.java

License:Apache License

/**
 * Draws the opaque or translucent elements of a chunk.
 *
 * @param type The type of vertices to render
 *//*from  www .j  a  v a2  s  .  com*/
public void render(ChunkMesh.RENDER_TYPE type) {
    GL11.glPushMatrix();
    GL11.glTranslatef(getPosition().x * getChunkDimensionX() - _parent.getRenderingReferencePoint().x,
            getPosition().y * getChunkDimensionY() - _parent.getRenderingReferencePoint().y,
            getPosition().z * getChunkDimensionZ() - _parent.getRenderingReferencePoint().z);

    // Render the generated chunk mesh
    if (_activeMesh != null) {
        _activeMesh.render(type);
    }

    GL11.glPopMatrix();
}

From source file:com.github.begla.blockmania.world.physics.BulletPhysicsRenderer.java

License:Apache License

public void render() {
    for (BlockRigidBody b : _blocks) {
        Transform t = new Transform();
        b.getMotionState().getWorldTransform(t);

        GL11.glPushMatrix();//from  www.j  ava  2  s . c om

        FloatBuffer mBuffer = BufferUtils.createFloatBuffer(16);
        float[] mFloat = new float[16];
        t.getOpenGLMatrix(mFloat);

        mBuffer.put(mFloat);
        mBuffer.flip();

        GL11.glTranslatef(-_parent.getPlayer().getPosition().x, -_parent.getPlayer().getPosition().y,
                -_parent.getPlayer().getPosition().z);
        GL11.glMultMatrix(mBuffer);

        float lightValue = calcLightValueForTransform(t);
        int lightRef = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("block"), "light");
        GL20.glUniform1f(lightRef, lightValue);

        BlockManager.getInstance().getBlock(b.getType()).render();
        GL11.glPopMatrix();
    }
}

From source file:com.golden.gamedev.engine.lwjgl.LWJGLGraphics.java

License:Open Source License

/** ************************************************************************* */

public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
    this.startPainting();

    // store the current model matrix
    GL11.glPushMatrix();/*from w w  w.j  a  v  a  2 s  . c om*/

    // bind to the appropriate texture for this sprite
    Texture texture = this.textureLoader.getTexture((BufferedImage) img);
    texture.bind();

    // translate to the right location and prepare to draw
    GL11.glTranslatef(x, y, 0);

    // draw a quad textured to match the sprite
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(0, 0);

    GL11.glTexCoord2f(0, texture.getHeight());
    GL11.glVertex2f(0, texture.getImageHeight());

    GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
    GL11.glVertex2f(texture.getImageWidth(), texture.getImageHeight());

    GL11.glTexCoord2f(texture.getWidth(), 0);
    GL11.glVertex2f(texture.getImageWidth(), 0);
    GL11.glEnd();

    // restore the model view matrix to prevent contamination
    GL11.glPopMatrix();

    this.endPainting();

    return true;
}

From source file:com.golden.gamedev.engine.lwjgl.LWJGLGraphics.java

License:Open Source License

public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
    this.startPainting();

    GL11.glPushMatrix();//w ww  .j  ava  2 s  . c o m

    Texture texture = this.textureLoader.getTexture((BufferedImage) img);
    texture.bind();

    GL11.glTranslatef(x, y, 0);

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(0, 0);

    GL11.glTexCoord2f(0, texture.getHeight());
    GL11.glVertex2f(0, height);

    GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
    GL11.glVertex2f(width, height);

    GL11.glTexCoord2f(texture.getWidth(), 0);
    GL11.glVertex2f(width, 0);
    GL11.glEnd();

    GL11.glPopMatrix();

    this.endPainting();

    return true;
}

From source file:com.hea3ven.pandoraschest.client.model.ModelBaseChest.java

License:Open Source License

public void render(TileEntityBaseChest chest, double x, double y, double z) {
    GL11.glPushMatrix();/*w  w  w. j a v  a2  s .  c om*/

    GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
    GL11.glRotatef(-90.0f + chest.getRotation() * -90.0f, 0.0f, 1.0f, 0.0f);

    chest.getAnimationState().render();

    GL11.glPopMatrix();
}

From source file:com.hea3ven.pandoraschest.client.model.ModelFluorecentSpot.java

License:Open Source License

public void render(TileEntityFluorecentBlock chest, double x, double y, double z) {

    int meta = chest.getBlockMetadata();

    GL11.glPushMatrix();/* w w w.  j av  a2 s  .c  om*/

    GL11.glTranslatef((float) x + 0.5f, (float) y, (float) z + 0.5f);
    if (meta != 0) {
        GL11.glTranslatef((float) 0.0f, (float) 0.5f, (float) 0.0f);
        GL11.glRotatef(90.0f * (meta - 1) + 90.0f, 0.0f, 1.0f, 0.0f);
        GL11.glRotatef(-90.f, 1.0f, 0.0f, 0.0f);
        GL11.glTranslatef((float) 0.0f, (float) -0.5f, (float) 0.0f);
    }
    // GL11.glTranslated((float) 2.0f*x, (float) 2.0f*y, (float) 2.0f*z);

    // GL11.glTranslatef((float) 0.5f, (float) 0.0f, (float)0.5f);

    // this.renderAnimation(chest.getAnimationFrame());
    ModColladaModel.getModelManager().getModel(modelResource).renderAll();

    GL11.glPopMatrix();
}

From source file:com.hea3ven.pandoraschest.client.model.ModelFluorecentSpot.java

License:Open Source License

public void renderItem() {
    GL11.glPushMatrix();//from   ww w  . jav  a2s .co  m
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glTranslatef(0.0f, -0.5f, 0.0f);

    ModColladaModel.getModelManager().getModel(modelResource).renderAll();

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glPopMatrix();
}

From source file:com.hea3ven.pandoraschest.client.model.ModelFluorecentTube.java

License:Open Source License

public void render(TileEntityFluorecentTubeBlock chest, double x, double y, double z) {

    int meta = chest.getBlockMetadata();

    GL11.glPushMatrix();/*from   www .  ja v a 2  s  .c om*/

    GL11.glTranslatef((float) x + 0.5f, (float) y, (float) z + 0.5f);
    if (meta != 0) {
        GL11.glTranslatef((float) 0.0f + (chest.getXOffset() / 2.0f),
                (float) 0.5f + (chest.getYOffset() / 2.0f), (float) 0.0f + (chest.getZOffset() / 2.0f));
        GL11.glRotatef(90.0f * (meta - 1) + 90.0f + ((chest.getYOffset() == 0) ? 90.0f : 0.0f), 0.0f, 1.0f,
                0.0f);
        if (chest.getYOffset() != 0)
            GL11.glRotatef(-90.f, 1.0f, 0.0f, 0.0f);
        else
            GL11.glRotatef(-90.f, 0.0f, 0.0f, 1.0f);
        GL11.glTranslatef((float) 0.0f, (float) -0.5f, (float) 0.0f);
    } else {
        GL11.glTranslatef(chest.getXOffset() / 2.0f, chest.getYOffset() / 2.0f, chest.getZOffset() / 2.0f);
        if (chest.getXOffset() != 0)
            GL11.glRotatef(90.f, 0.0f, 1.0f, 0.0f);
    }
    // GL11.glTranslated((float) 2.0f*x, (float) 2.0f*y, (float) 2.0f*z);

    // GL11.glTranslatef((float) 0.5f, (float) 0.0f, (float)0.5f);

    // this.renderAnimation(chest.getAnimationFrame());
    ModColladaModel.getModelManager().getModel(modelResource).renderAll();

    GL11.glPopMatrix();
}

From source file:com.hilburn.dimensionguard.client.DisabledRenderer.java

License:Open Source License

@Override
public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) {
    ItemStack thisStack = ItemStack//from w  w  w.j  a v  a  2s .  c om
            .loadItemStackFromNBT((NBTTagCompound) itemStack.stackTagCompound.getTag("ItemStack"));

    boolean isInventory = type == ItemRenderType.INVENTORY;

    Tessellator tess = Tessellator.instance;
    FontRenderer fontRenderer = mc.fontRenderer;
    TextureManager textureManager = mc.getTextureManager();
    GL11.glPushMatrix();
    Item item = thisStack.getItem();
    Block block = Block.getBlockFromItem(item);

    if (thisStack != null && block != null && block.getRenderBlockPass() != 0) {
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_CULL_FACE);
        OpenGlHelper.glBlendFunc(770, 771, 1, 0);
    }
    IItemRenderer storedRenderer = MinecraftForgeClient.getItemRenderer(thisStack, type);
    //======Handles Special Blocks and Items======
    if (storedRenderer != null) {
        storedRenderer.renderItem(type, thisStack, data);
    } else {
        if (thisStack.getItemSpriteNumber() == 0 && item instanceof ItemBlock
                && RenderBlocks.renderItemIn3d(block.getRenderType())) {
            //=====Handles regular blocks======
            textureManager.bindTexture(textureManager.getResourceLocation(0));
            switch (type) {
            case EQUIPPED_FIRST_PERSON:
            case EQUIPPED:
            case ENTITY:
                GL11.glTranslatef(0.5F, 0.5F, 0.5F);
            default:
            }
            if (thisStack != null && block != null && block.getRenderBlockPass() != 0) {
                GL11.glDepthMask(false);
                renderBlocksIr.renderBlockAsItem(block, thisStack.getItemDamage(), 1.0F);
                GL11.glDepthMask(true);
            } else {
                renderBlocksIr.renderBlockAsItem(block, thisStack.getItemDamage(), 1.0F);
            }
        } else {
            //=======Handles Regular Items======
            if (isInventory) {
                renderItem.renderItemIntoGUI(fontRenderer, textureManager, thisStack, 0, 0);
            } else {
                GL11.glEnable(GL12.GL_RESCALE_NORMAL);
                switch (type) {
                case EQUIPPED_FIRST_PERSON:
                    //TODO: get items to render in the right place
                    GL11.glRotated(90F, 0F, 1F, 0F);
                    GL11.glTranslatef(-1F, 0.5F, 0F);
                    break;
                case EQUIPPED:
                    GL11.glRotated(90F, 0F, 1F, 0F);
                    GL11.glTranslatef(-1F, 0.5F, 0F);
                    GL11.glRotated(90F, 1F, 0F, 0F);
                    //GL11.glTranslatef(0, -4 / 16f, 0);
                    break;
                case ENTITY:
                    //GL11.glTranslatef(-0.5f, 0f, 1f / 16f); // correction of the rotation point when items lie on the ground
                default:
                }

                IIcon icon = thisStack.getIconIndex();
                float xMax;
                float yMin;
                float xMin;
                float yMax;
                float depth = 1f / 16f;

                float width;
                float height;
                float xDiff;
                float yDiff;
                float xSub;
                float ySub;

                xMin = icon.getMinU();
                xMax = icon.getMaxU();
                yMin = icon.getMinV();
                yMax = icon.getMaxV();
                width = icon.getIconWidth();
                height = icon.getIconHeight();
                xDiff = xMin - xMax;
                yDiff = yMin - yMax;
                xSub = 0.5f * (xMax - xMin) / width;
                ySub = 0.5f * (yMax - yMin) / height;

                //=====Front and back=====
                tess.startDrawingQuads();
                tess.setNormal(0, 0, 1);
                tess.addVertexWithUV(0, 0, 0, xMax, yMax);
                tess.addVertexWithUV(1, 0, 0, xMin, yMax);
                tess.addVertexWithUV(1, 1, 0, xMin, yMin);
                tess.addVertexWithUV(0, 1, 0, xMax, yMin);
                tess.draw();

                tess.startDrawingQuads();
                tess.setNormal(0, 0, -1);
                tess.addVertexWithUV(0, 1, -depth, xMax, yMin);
                tess.addVertexWithUV(1, 1, -depth, xMin, yMin);
                tess.addVertexWithUV(1, 0, -depth, xMin, yMax);
                tess.addVertexWithUV(0, 0, -depth, xMax, yMax);
                tess.draw();

                // =========Sides============
                tess.startDrawingQuads();
                tess.setNormal(-1, 0, 0);
                float pos;
                float iconPos;
                float w = width, m = xMax, d = xDiff, s = xSub;
                for (int k = 0, e = (int) w; k < e; ++k) {
                    pos = k / w;
                    iconPos = m + d * pos - s;
                    tess.addVertexWithUV(pos, 0, -depth, iconPos, yMax);
                    tess.addVertexWithUV(pos, 0, 0, iconPos, yMax);
                    tess.addVertexWithUV(pos, 1, 0, iconPos, yMin);
                    tess.addVertexWithUV(pos, 1, -depth, iconPos, yMin);
                }
                tess.draw();
                tess.startDrawingQuads();
                tess.setNormal(1, 0, 0);
                float posEnd;
                w = width;
                m = xMax;
                d = xDiff;
                s = xSub;
                float d2 = 1f / w;
                for (int k = 0, e = (int) w; k < e; ++k) {
                    pos = k / w;
                    iconPos = m + d * pos - s;
                    posEnd = pos + d2;
                    tess.addVertexWithUV(posEnd, 1, -depth, iconPos, yMin);
                    tess.addVertexWithUV(posEnd, 1, 0, iconPos, yMin);
                    tess.addVertexWithUV(posEnd, 0, 0, iconPos, yMax);
                    tess.addVertexWithUV(posEnd, 0, -depth, iconPos, yMax);
                }
                tess.draw();
                tess.startDrawingQuads();
                tess.setNormal(0, 1, 0);
                float h = height;
                m = yMax;
                d = yDiff;
                s = ySub;
                d2 = 1f / h;
                for (int k = 0, e = (int) h; k < e; ++k) {
                    pos = k / h;
                    iconPos = m + d * pos - s;
                    posEnd = pos + d2;
                    tess.addVertexWithUV(0, posEnd, 0, xMax, iconPos);
                    tess.addVertexWithUV(1, posEnd, 0, xMin, iconPos);
                    tess.addVertexWithUV(1, posEnd, -depth, xMin, iconPos);
                    tess.addVertexWithUV(0, posEnd, -depth, xMax, iconPos);
                }
                tess.draw();
                tess.startDrawingQuads();
                tess.setNormal(0, -1, 0);
                h = height;
                m = yMax;
                d = yDiff;
                s = ySub;
                for (int k = 0, e = (int) h; k < e; ++k) {
                    pos = k / h;
                    iconPos = m + d * pos - s;
                    tess.addVertexWithUV(1, pos, 0, xMin, iconPos);
                    tess.addVertexWithUV(0, pos, 0, xMax, iconPos);
                    tess.addVertexWithUV(0, pos, -depth, xMax, iconPos);
                    tess.addVertexWithUV(1, pos, -depth, xMin, iconPos);
                }
                tess.draw();
                GL11.glDisable(GL12.GL_RESCALE_NORMAL);
            }
        }
    }

    if (thisStack != null && block != null && block.getRenderBlockPass() != 0) {
        GL11.glDisable(GL11.GL_BLEND);
    }

    GL11.glPopMatrix();

    if (isInventory) {
        renderItem.renderItemIntoGUI(fontRenderer, textureManager, itemStack, 0, 0);
        //TODO: only renders on items, not blocks - fix
    }
}

From source file:com.irr310.i3d.scene.element.I3dElement.java

License:Open Source License

/**
 * Internal public method Mthode principal du rendu d'un lment. Cette
 * mthode appelle le code de rendu spcifique de l'lment via la mthode
 * doDisplay si ncessaire./*from w  ww. j a  v a2  s  . c o m*/
 * 
 * @param gl
 *            context gl du rendu
 * @param camera
 *            point de vue
 */
final public void display(I3dCamera camera) {
    if (!visible) {
        return;
    }

    if (!inited) {
        init();
    }

    GL11.glPushMatrix();
    if (transformMatrix != null) {
        GL11.glMultMatrix(transformMatrix);
    } else {
        if (rotation.x != 0) {
            GL11.glRotatef(rotation.x, 1, 0, 0);
        }
        if (rotation.y != 0) {
            GL11.glRotatef(rotation.y, 0, 1, 0);
        }
        if (rotation.z != 0) {
            GL11.glRotatef(rotation.z, 0, 0, 1);
        }

        if (position.x != 0 || position.y != 0 || position.z != 0) {
            GL11.glTranslatef(position.x, position.y, position.z);
        }
    }

    if (scale.x != 1 || scale.y != 1 || scale.z != 1) {
        GL11.glScalef(scale.x, scale.y, scale.z);
    }

    animation.preDisplay();

    if (animation.doDisplay()) {

        if (showShape) {
            doDisplay(camera);
        }

        if (showBoundingBox) {
            getBoundingBox().display();
        }
    }
    animation.postDisplay();

    GL11.glPopMatrix();
}