Example usage for org.lwjgl.opengl GL11 glBindTexture

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

Introduction

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

Prototype

public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture) 

Source Link

Document

Binds the a texture to a texture target.

Usage

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static void glBindTexture(int a, int b) {
    GL11.glBindTexture(a, b);
    switch (a) {/*  w ww. j a  v a  2  s . c o m*/
    case GL_TEXTURE_1D:
        textureUnits1d[activeTexture] = b;
        break;
    case GL_TEXTURE_2D:
        textureUnits2d[activeTexture] = b;
        break;
    case GL_TEXTURE_3D:
        textureUnits3d[activeTexture] = b;
        break;
    case GL_TEXTURE_1D_ARRAY:
        textureUnits1dArr[activeTexture] = b;
        break;
    case GL_TEXTURE_2D_ARRAY:
        textureUnits2dArr[activeTexture] = b;
        break;
    case GL_TEXTURE_RECTANGLE:
        textureUnitsRect[activeTexture] = b;
        break;
    case GL_TEXTURE_CUBE_MAP:
        textureUnitsCube[activeTexture] = b;
        break;
    case GL_TEXTURE_CUBE_MAP_ARRAY:
        textureUnitsCubeArr[activeTexture] = b;
        break;
    case GL_TEXTURE_BUFFER:
        textureUnitsBuf[activeTexture] = b;
        break;
    case GL_TEXTURE_2D_MULTISAMPLE:
        textureUnitsSampled[activeTexture] = b;
        break;
    case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
        textureUnitsSampledArr[activeTexture] = b;
        break;
    }
}

From source file:uk.codingbadgers.bUpload.gui.UploadHistoryGUI.java

License:Open Source License

/**
 * Draw the container image to the screen
 * /* www . jav a 2  s  . co  m*/
 * @param
 * @param
 * @param
 */
public void drawScreen(int i, int j, float f) {
    Minecraft minecraft = Minecraft.getMinecraft();
    drawDefaultBackground();
    // load our container image
    minecraft.renderEngine.func_110577_a(new ResourceLocation("bUpload:textures/gui/bupload-history.png"));
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    drawTexturedModalRect((width / 2) - (COTAINER_WIDTH / 2), (height / 2) - (CONTAINER_HIGHT / 2), 0, 0,
            COTAINER_WIDTH, CONTAINER_HIGHT);
    UploadedImage imageInfo = m_mod.getUploadedImage(m_currentImage);

    if (imageInfo != null) {
        // draw the image information
        int yOffset = 132;
        drawCenteredString(minecraft.fontRenderer, imageInfo.getName(), (width / 2),
                ((height / 2) - (CONTAINER_HIGHT / 2)) + yOffset, 0xFFFFFFFF);
        yOffset += 16;

        if (!imageInfo.isLocal()) {
            drawCenteredString(minecraft.fontRenderer, imageInfo.getUrl(), (width / 2),
                    ((height / 2) - (CONTAINER_HIGHT / 2)) + yOffset, 0xFFFFAA00);
        } else {
            drawCenteredString(minecraft.fontRenderer, I18n.func_135053_a("image.history.open"), (width / 2),
                    ((height / 2) - (CONTAINER_HIGHT / 2)) + yOffset, 0xFFFFAA00);
        }

        // draw the image preview
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, imageInfo.getImageID());
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        drawTexturedModalRectSized((width / 2) - (COTAINER_WIDTH / 2) + 8,
                (height / 2) - (CONTAINER_HIGHT / 2) + 18, 0, 0, 160, 101, 256, 256);
    } else {
        drawCenteredString(minecraft.fontRenderer, I18n.func_135053_a("image.history.empty"), (width / 2),
                ((height / 2) - (CONTAINER_HIGHT / 2)) + 132, 0xFFFFFFFF);
    }

    super.drawScreen(i, j, f);
}

From source file:v9t9.gui.client.swt.gl.Texture.java

License:Open Source License

/**
 * Bind the specified GL context to a texture
 *
 * @param gl The GL context to bind to
 */
public void bind() {
    GL11.glBindTexture(target, textureID);
}

From source file:v9t9.gui.client.swt.gl.TextureLoader.java

License:Open Source License

/**
 * Load a texture into OpenGL from a image reference on
 * disk.//  ww w  . j  a  va  2 s . c  om
 *
 * @param resourceName The location of the resource to load
 * @param target The GL target to load the texture against
 * @param dstPixelFormat The pixel format of the screen
 * @param minFilter The minimising filter
 * @param magFilter The magnification filter
 * @return The loaded texture
 * @throws IOException Indicates a failure to access the resource
 */
public Texture getTexture(String resourceName, int target, int dstPixelFormat, int minFilter, int magFilter)
        throws IOException {
    int srcPixelFormat = 0;

    // create the texture ID for this texture 
    int textureID = createTextureID();
    Texture texture = new Texture(target, textureID);

    // bind this texture 
    GL11.glBindTexture(target, textureID);

    BufferedImage bufferedImage = loadImage(resourceName);
    texture.setWidth(bufferedImage.getWidth());
    texture.setHeight(bufferedImage.getHeight());

    if (bufferedImage.getColorModel().hasAlpha()) {
        srcPixelFormat = GL11.GL_RGBA;
    } else {
        srcPixelFormat = GL11.GL_RGB;
    }

    // convert that image into a byte buffer of texture data 
    ByteBuffer textureBuffer = convertImageData(bufferedImage, texture);

    if (target == GL11.GL_TEXTURE_2D) {
        GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
        GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter);
    }

    // produce a texture from the byte buffer
    GL11.glTexImage2D(target, 0, dstPixelFormat, get2Fold(bufferedImage.getWidth()),
            get2Fold(bufferedImage.getHeight()), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer);

    return texture;
}

From source file:vazkii.botania.client.gui.lexicon.button.GuiButtonCategory.java

License:Open Source License

@Override
public void drawButton(@Nonnull Minecraft mc, int mx, int my) {
    boolean inside = mx >= xPosition && my >= yPosition && mx < xPosition + width && my < yPosition + height;
    if (inside)//from   www  .jav  a  2 s.  c  om
        ticksHovered = Math.min(time, ticksHovered + gui.timeDelta);
    else
        ticksHovered = Math.max(0F, ticksHovered - gui.timeDelta);

    if (resource == null) {
        if (category == null)
            resource = fallbackResource;
        else
            resource = category.getIcon();
        if (resource == null)
            resource = fallbackResource;
    }

    float s = 1F / 32F;

    GlStateManager.pushMatrix();
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.scale(0.5F, 0.5F, 0.5F);
    GlStateManager.color(1F, 1F, 1F, 1F);

    if (!boundStencil) { // Allow for the texture manager to take care of the ResourceLocation before we use it directly with gl
        mc.renderEngine.bindTexture(stencilResource);
        boundStencil = true;
    }
    mc.renderEngine.bindTexture(resource);

    int texture = 0;
    boolean shaders = ShaderHelper.useShaders();

    if (shaders) {
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + ConfigHandler.glSecondaryTextureUnit);
        texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    }

    ShaderHelper.useShader(ShaderHelper.categoryButton, shaderCallback);
    RenderHelper.drawTexturedModalRect(xPosition * 2, yPosition * 2, zLevel * 2, 0, 0, 32, 32, s, s);
    ShaderHelper.releaseShader();

    if (shaders) {
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + ConfigHandler.glSecondaryTextureUnit);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB);
    }

    GlStateManager.popMatrix();

    if (inside)
        gui.categoryHighlight = I18n.format(getTooltipText());
}

From source file:vazkii.psi.client.core.handler.HUDHandler.java

@SideOnly(Side.CLIENT)
public void drawPsiBar(ScaledResolution res, float pticks) {
    Minecraft mc = Minecraft.getMinecraft();
    ItemStack cadStack = PsiAPI.getPlayerCAD(mc.thePlayer);

    if (cadStack == null)
        return;/* w  w  w . j a  v a  2 s. c  om*/

    ICAD cad = (ICAD) cadStack.getItem();
    PlayerData data = PlayerDataHandler.get(mc.thePlayer);
    if (data.level == 0 && !mc.thePlayer.capabilities.isCreativeMode)
        return;

    GlStateManager.pushMatrix();
    int scaleFactor = res.getScaleFactor();

    if (scaleFactor > ConfigHandler.maxPsiBarScale) {
        int guiScale = mc.gameSettings.guiScale;

        mc.gameSettings.guiScale = ConfigHandler.maxPsiBarScale;
        res = new ScaledResolution(mc);
        mc.gameSettings.guiScale = guiScale;

        float s = (float) ConfigHandler.maxPsiBarScale / (float) scaleFactor;
        GlStateManager.scale(s, s, s);
    }

    boolean right = ConfigHandler.psiBarOnRight;

    int pad = 3;
    int width = 32;
    int height = 140;

    int x = -pad;
    if (right)
        x = res.getScaledWidth() + pad - width;
    int y = res.getScaledHeight() / 2 - height / 2;

    if (!registeredMask) {
        mc.renderEngine.bindTexture(psiBarMask);
        mc.renderEngine.bindTexture(psiBarShatter);
        registeredMask = true;
    }
    mc.renderEngine.bindTexture(psiBar);
    Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 0, width, height, 64, 256);

    x += 8;
    y += 26;

    width = 16;
    height = 106;

    float r = 0.6F;
    float g = 0.65F;
    float b = 1F;

    int origHeight = height;
    int origY = y;
    int v = 0;
    int max = data.getTotalPsi();

    int texture = 0;
    boolean shaders = ShaderHandler.useShaders();

    if (shaders) {
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + secondaryTextureUnit);
        texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    }

    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    for (Deduction d : data.deductions) {
        float a = d.getPercentile(pticks);
        GlStateManager.color(r, g, b, a);
        height = (int) Math.ceil(origHeight * (double) d.deduct / max);
        int effHeight = (int) (origHeight * (double) d.current / max);
        v = origHeight - effHeight;
        y = origY + v;

        ShaderHandler.useShader(ShaderHandler.psiBar, generateCallback(a, d.shatter));
        Gui.drawModalRectWithCustomSizedTexture(x, y, 32, v, width, height, 64, 256);
    }

    float textY = origY;
    if (max > 0) {
        height = (int) ((double) origHeight * (double) data.availablePsi / max);
        v = origHeight - height;
        y = origY + v;

        if (data.availablePsi != data.lastAvailablePsi) {
            float textHeight = (float) (origHeight
                    * (data.availablePsi * pticks + data.lastAvailablePsi * (1.0 - pticks)) / max);
            textY = origY + (origHeight - textHeight);
        } else
            textY = y;
    } else
        height = 0;

    GlStateManager.color(r, g, b);
    ShaderHandler.useShader(ShaderHandler.psiBar, generateCallback(1F, false));
    Gui.drawModalRectWithCustomSizedTexture(x, y, 32, v, width, height, 64, 256);
    ShaderHandler.releaseShader();

    if (shaders) {
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + secondaryTextureUnit);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB);
    }

    GlStateManager.color(1F, 1F, 1F);

    GlStateManager.pushMatrix();
    GlStateManager.translate(0F, textY, 0F);
    width = 44;
    height = 3;

    String s1 = "" + data.availablePsi;
    String s2 = "" + cad.getStoredPsi(cadStack);

    int offBar = 22;
    int offStr1 = 7 + mc.fontRendererObj.getStringWidth(s1);
    int offStr2 = 7 + mc.fontRendererObj.getStringWidth(s2);

    if (!right) {
        offBar = 6;
        offStr1 = -23;
        offStr2 = -23;
    }

    Color color = new Color(cad.getSpellColor(cadStack));
    GlStateManager.color(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F);

    Gui.drawModalRectWithCustomSizedTexture(x - offBar, -2, 0, 140, width, height, 64, 256);
    mc.fontRendererObj.drawStringWithShadow(s1, x - offStr1, -11, 0xFFFFFF);
    GlStateManager.popMatrix();

    GlStateManager.pushMatrix();
    GlStateManager.translate(0F, Math.max(textY + 3, origY + 100), 0F);
    mc.fontRendererObj.drawStringWithShadow(s2, x - offStr2, 0, 0xFFFFFF);
    GlStateManager.popMatrix();
    GlStateManager.popMatrix();
}

From source file:vazkii.psi.client.core.handler.HUDHandler.java

@SideOnly(Side.CLIENT)
private static Consumer<Integer> generateCallback(final float percentile, final boolean shatter) {
    Minecraft mc = Minecraft.getMinecraft();
    return (Integer shader) -> {
        int percentileUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "percentile");
        int imageUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "image");
        int maskUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "mask");

        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture(psiBar).getGlTextureId());
        ARBShaderObjects.glUniform1iARB(imageUniform, 0);

        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + secondaryTextureUnit);

        GlStateManager.enableTexture2D();
        GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D,
                mc.renderEngine.getTexture(shatter ? psiBarShatter : psiBarMask).getGlTextureId());
        ARBShaderObjects.glUniform1iARB(maskUniform, secondaryTextureUnit);

        ARBShaderObjects.glUniform1fARB(percentileUniform, percentile);
    };//from  w ww .  j a v  a 2  s  .  com
}

From source file:vazkii.tinkerer.client.hud.HudElementVignette.java

License:Creative Commons License

private void renderVignette(int color) {
    Minecraft mc = MiscHelper.getMc();// www.ja v  a2  s .  co m
    ScaledResolution var5 = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
    int par2 = var5.getScaledWidth();
    int par3 = var5.getScaledHeight();

    GL11.glPushMatrix();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDepthMask(false);
    GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR);
    Color colorRGB = new Color(color);
    GL11.glColor4f(colorRGB.getRed(), colorRGB.getGreen(), colorRGB.getBlue(), 1.0F);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture("%blur%/misc/vignette.png"));
    Tessellator var4 = Tessellator.instance;
    var4.startDrawingQuads();
    var4.addVertexWithUV(0.0D, par3, -90.0D, 0.0D, 1.0D);
    var4.addVertexWithUV(par2, par3, -90.0D, 1.0D, 1.0D);
    var4.addVertexWithUV(par2, 0.0D, -90.0D, 1.0D, 0.0D);
    var4.addVertexWithUV(0.0D, 0.0D, -90.0D, 0.0D, 0.0D);
    var4.draw();
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glPopMatrix();
}

From source file:vazkii.tinkerer.client.tilerender.TileEntityRenderVoidGateway.java

License:Creative Commons License

@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float ticks) {
    VoidEntry entry = VoidMap.theMap.getEntryAtCoord(tile.xCoord, tile.zCoord);

    if (entry != null && entry.stack != null) {
        ItemStack stack = entry.stack.copy();
        stack.stackSize = 1;//from w  w  w  .  j av a  2s. c o m

        GL11.glPushMatrix();
        GL11.glTranslatef((float) x + 0.5F, (float) y + 0.1F,
                (float) z + 0.4F + MiscReference.MODEL_DEFAULT_RENDER_SCALE);
        GL11.glRotatef((float) ClientTickHandler.elapsedClientTicks % 360L / 20.0F * (180F / (float) Math.PI),
                0.0F, 1.0F, 0.0F);
        Minecraft mc = MiscHelper.getMc();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine
                .getTexture(stack.getItem() instanceof ItemBlock ? "/terrain.png" : "/gui/items.png"));
        Tessellator var5 = Tessellator.instance;
        RenderBlocks var6 = new RenderBlocks();
        if (stack.getItem() instanceof ItemBlock
                && RenderBlocks.renderItemIn3d(Block.blocksList[stack.itemID].getRenderType())) {
            GL11.glScalef(0.5F, 0.5F, 0.5F);
            GL11.glTranslatef(0F, 0.9F, 0F);
            var6.renderBlockAsItem(Block.blocksList[stack.itemID], stack.getItemDamage(), 1F);

        } else {
            int renderPass = 0;
            GL11.glScalef(0.75F, 0.75F, 0.75F);
            GL11.glRotatef(
                    (float) ClientTickHandler.elapsedClientTicks % 360L / 20.0F * (180F / (float) Math.PI),
                    0.0F, 1.0F, 0.0F);
            GL11.glTranslatef(-0.5F, 0F, -MiscReference.MODEL_DEFAULT_RENDER_SCALE);
            do {
                Icon icon = stack.getItem().getIcon(stack, renderPass);
                if (icon != null) {
                    Color color = new Color(stack.getItem().getColorFromItemStack(stack, renderPass));

                    GL11.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
                    float f = icon.getMinU();
                    float f1 = icon.getMaxU();
                    float f2 = icon.getMinV();
                    float f3 = icon.getMaxV();
                    // TODO Is this correct?
                    ItemRenderer.renderItemIn2D(var5, f1, f2, f, f3, icon.getOriginX(), icon.getOriginY(),
                            MiscReference.MODEL_DEFAULT_RENDER_SCALE);
                    GL11.glColor3f(1F, 1F, 1F);
                }
                renderPass++;
            } while (renderPass < stack.getItem().getRenderPasses(stack.getItemDamage()));
        }

        GL11.glColor4f(1F, 1F, 1F, 1F);
        GL11.glPopMatrix();
    } else {
        GL11.glPushMatrix();
        GL11.glColor4f(1F, 1F, 1F, 1F);
        GL11.glTranslatef((float) x + 2.5F, (float) y - 0.5F, (float) z + 0.5F);
        GL11.glRotatef(180F, 0.5F, 0F, 0.5F);
        RenderHelper.renderStar(0x140025, 0.03F, 0.03F, 0.03F);
        GL11.glPopMatrix();
    }
}

From source file:vazkii.tinkerer.gui.GuiResearchGame.java

License:Creative Commons License

public void drawPlayerHead() {
    int tex = mc.renderEngine.getTextureForDownloadableImage(mc.thePlayer.skinUrl, mc.thePlayer.getTexture());

    mc.renderEngine.bindTexture(mc.thePlayer.getTexture());

    if (tex >= 0) {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex);
        mc.renderEngine.resetBoundTexture();
    }//from  w w w  .j av a 2  s. c om

    Tessellator tessellator = Tessellator.instance;
    GL11.glPushMatrix();
    GL11.glScalef(2F, 2F, 2F);
    int x = (xStart + 62) / 2;
    int y = (yStart + 62) / 2;

    float xU = 1F / 64F;
    float yU = 1F / 32F;

    tessellator.startDrawingQuads();
    tessellator.addVertexWithUV(x + 0, y + 8, zLevel, xU * 8, yU * 16);
    tessellator.addVertexWithUV(x + 8, y + 8, zLevel, xU * 16, yU * 16);
    tessellator.addVertexWithUV(x + 8, y + 0, zLevel, xU * 16, yU * 8);
    tessellator.addVertexWithUV(x + 0, y + 0, zLevel, xU * 8, yU * 8);
    tessellator.draw();

    tessellator.startDrawingQuads();
    tessellator.addVertexWithUV(x + 0, y + 8, zLevel, xU * 40, yU * 16);
    tessellator.addVertexWithUV(x + 8, y + 8, zLevel, xU * 48, yU * 16);
    tessellator.addVertexWithUV(x + 8, y + 0, zLevel, xU * 48, yU * 8);
    tessellator.addVertexWithUV(x + 0, y + 0, zLevel, xU * 40, yU * 8);
    tessellator.draw();

    GL11.glPopMatrix();

    fontRenderer.setUnicodeFlag(true);
    final int marks = 8;
    final int degChangePerMark = 360 / marks;
    final double startDeg = ElementalTinkerer.proxy.getGameTicksElapsed() * 4 % 360D;
    final int radius = (int) (20 + Math.cos(ElementalTinkerer.proxy.getGameTicksElapsed() / 5D) * 3);

    for (int i = 0; i < marks; i++) {
        Point point = MathHelper.getPointInCircle(new Point(xStart + 69, yStart + 67),
                (int) (startDeg + degChangePerMark * i), radius);
        fontRenderer.drawStringWithShadow("?", point.x, point.y, 0xFFFFFF);
    }

    fontRenderer.setUnicodeFlag(false);
}