Java Code Examples for net.minecraft.client.renderer.GlStateManager#bindTexture()

The following examples show how to use net.minecraft.client.renderer.GlStateManager#bindTexture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextureUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void prepareTexture(int target, int texture, int min_mag_filter, int wrap) {
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, min_mag_filter);
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, min_mag_filter);
    if(target == GL11.GL_TEXTURE_2D)
        GlStateManager.bindTexture(target);
    else
        GL11.glBindTexture(target, texture);

    switch (target) {
        case GL12.GL_TEXTURE_3D:
            GL11.glTexParameteri(target, GL12.GL_TEXTURE_WRAP_R, wrap);
        case GL11.GL_TEXTURE_2D:
            GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_T, wrap);
        case GL11.GL_TEXTURE_1D:
            GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_S, wrap);
    }
}
 
Example 2
Source File: TextureURL.java    From Custom-Main-Menu with MIT License 6 votes vote down vote up
@Override
public void bind()
{
	if (this.textureID != -1)
	{
		GlStateManager.bindTexture(this.textureID);
	}
	else
	{
		if (bi != null)
		{
			setTextureID(TextureUtil.uploadTextureImageAllocate(GL11.glGenTextures(), bi, false, false));
			bind();
			return;
		}
		CustomMainMenu.bindTransparent();
	}
}
 
Example 3
Source File: TextureApng.java    From Custom-Main-Menu with MIT License 5 votes vote down vote up
@Override
public void bind()
{
	if (!loaded)
	{
		load();
		loaded = true;
	}

	if (errored)
	{
		GlStateManager.bindTexture(TextureUtil.MISSING_TEXTURE.getGlTextureId());
		return;
	}
	
	while (System.currentTimeMillis() - lastTimeStamp >= currentFrameDelay)
	{
		currentFrame++;
		if (currentFrame > animationControl.numFrames - 1)
		{
			currentFrame = 0;
		}

		Frame f = frames.get(currentFrame);

		float numerator = f.control.delayNumerator;
		float denominator = f.control.delayDenominator > 0 ? f.control.delayDenominator : 100;

		this.lastTimeStamp += currentFrameDelay;
		this.currentFrameDelay = (int) ((numerator / denominator) * 1000);
	}

	GlStateManager.bindTexture(frameTextureID.get(frames.get(currentFrame)));
}
 
Example 4
Source File: GuiItemIconDumper.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private BufferedImage screenshot() {
    Framebuffer fb = Minecraft.getMinecraft().getFramebuffer();
    Dimension mcSize = GuiDraw.displayRes();
    Dimension texSize = mcSize;

    if (OpenGlHelper.isFramebufferEnabled())
        texSize = new Dimension(fb.framebufferTextureWidth, fb.framebufferTextureHeight);

    int k = texSize.width * texSize.height;
    if (pixelBuffer == null || pixelBuffer.capacity() < k) {
        pixelBuffer = BufferUtils.createIntBuffer(k);
        pixelValues = new int[k];
    }

    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    pixelBuffer.clear();

    if (OpenGlHelper.isFramebufferEnabled()) {
        GlStateManager.bindTexture(fb.framebufferTexture);
        GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
    } else {
        GL11.glReadPixels(0, 0, texSize.width, texSize.height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
    }

    pixelBuffer.get(pixelValues);
    TextureUtil.processPixelValues(pixelValues, texSize.width, texSize.height);

    BufferedImage img = new BufferedImage(mcSize.width, mcSize.height, BufferedImage.TYPE_INT_ARGB);
    if (OpenGlHelper.isFramebufferEnabled()) {
        int yOff = texSize.height - mcSize.height;
        for (int y = 0; y < mcSize.height; ++y)
            for (int x = 0; x < mcSize.width; ++x)
                img.setRGB(x, y, pixelValues[(y + yOff) * texSize.width + x]);
    } else {
        img.setRGB(0, 0, texSize.width, height, pixelValues, 0, texSize.width);
    }

    return img;
}
 
Example 5
Source File: RenderUtils.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void drawFilledCircle(int x, int y, float radius, int color) {
    GlStateManager.pushAttrib();
    GlStateManager.pushMatrix();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.disableTexture2D();

    GL11.glBegin(GL11.GL_TRIANGLE_FAN);

    for (int i = 0; i < 50; i++) {
        float px = x + radius * MathHelper.sin((float) (i * (6.28318530718 / 50)));
        float py = y + radius * MathHelper.cos((float) (i * (6.28318530718 / 50)));

        float alpha = (color >> 24 & 255) / 255.0F;
        float red = (color >> 16 & 255) / 255.0F;
        float green = (color >> 8 & 255) / 255.0F;
        float blue = (color & 255) / 255.0F;
        GL11.glColor4f(red, green, blue, alpha);

        GL11.glVertex2d(px, py);
    }

    GL11.glEnd();

    GlStateManager.enableTexture2D();
    GlStateManager.disableBlend();
    GlStateManager.popAttrib();
    GlStateManager.popMatrix();
    GlStateManager.bindTexture(0);
    GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
}
 
Example 6
Source File: LuminanceProducerImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public void getFrame(MissionInit missionInit, ByteBuffer buffer)
{
    final int width = getWidth();
    final int height = getHeight();

    // Render the Minecraft frame into our own FBO, at the desired size:
    OpenGlHelper.glUseProgram(shaderID);
    this.fbo.bindFramebuffer(true);
    Minecraft.getMinecraft().getFramebuffer().framebufferRenderExt(width, height, true);
    GlStateManager.bindTexture(this.fbo.framebufferTexture);
    GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL_RED, GL_UNSIGNED_BYTE, buffer);
    this.fbo.unbindFramebuffer();
    OpenGlHelper.glUseProgram(0);
}
 
Example 7
Source File: DynamicTextureMap.java    From VanillaFix with MIT License 5 votes vote down vote up
public void update() {
    minecraft.profiler.startSection("updateTextureMap");

    if (atlasNeedsExpansion) {
        atlasNeedsExpansion = false;

        minecraft.profiler.startSection("expandAtlas");

        int newWidth = stitcher.getImageWidth();
        int newHeight = stitcher.getImageHeight();
        LOGGER.info("Expanding '{}' atlas to {}x{}", basePath, newWidth, newHeight);

        TextureScaleInfo.textureId = -1;
        TextureUtil.allocateTextureImpl(getGlTextureId(), mipmapLevels, newWidth, newHeight);

        TextureScaleInfo.textureId = getGlTextureId();
        TextureScaleInfo.xScale = (double) DynamicStitcher.BASE_WIDTH / newWidth;
        TextureScaleInfo.yScale = (double) DynamicStitcher.BASE_HEIGHT / newHeight;

        GlStateManager.bindTexture(getGlTextureId());
        for (TextureAtlasSprite loadedSprite : stitcher.getAllSprites()) {
            TextureUtil.uploadTextureMipmap(loadedSprite.getFrameTextureData(0), loadedSprite.getIconWidth(), loadedSprite.getIconHeight(), loadedSprite.getOriginX(), loadedSprite.getOriginY(), false, false);
        }

        minecraft.profiler.endSection();
    }

    minecraft.profiler.startSection("uploadTexture");
    GlStateManager.bindTexture(getGlTextureId());
    for (TextureAtlasSprite sprite : spritesNeedingUpload) {
        spritesNeedingUpload.remove(sprite);
        TextureUtil.uploadTextureMipmap(sprite.getFrameTextureData(0), sprite.getIconWidth(), sprite.getIconHeight(), sprite.getOriginX(), sprite.getOriginY(), false, false);
    }
    minecraft.profiler.endSection();

    minecraft.profiler.endSection();
}
 
Example 8
Source File: CollapsibleTabComponent.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void render(int x, int y, int width, int mouseX, int mouseY) {
    super.render(x, y, width, mouseX, mouseY);

    tab.gui.getFont().drawString(label.replaceAll("_", " ").toUpperCase(), x + 3, y + 5, 0xffffff);

    GlStateManager.bindTexture(0);

    if (collapsed) {
        Icons.ARROW_UP_ALT.bind();
    } else {
        Icons.ARROW_DOWN_ALT.bind();
    }

    Gui.drawScaledCustomSizeModalRect(x + width - 20, y, 0, 0, 144, 144, 20, 20, 144, 144);

    if (collapsed) return;

    y += 18;
    x += 10;
    width -= 10;

    boolean right = false; // left right column stuff
    int prevH = 0;

    for (AbstractTabComponent comp : tmpf == null ? children : children.stream().filter(c -> c.filter(tmpf)).collect(Collectors.toList())) {
        if (parent != null) right = false;

        int x1 = right ? x + width / 2 : x;
        comp.render(x1, y, parent != null ? width : width / 2, mouseX, mouseY);

        if (mouseX >= (x1) && mouseX <= (x1) + (parent != null ? width : width / 2) && mouseY >= y && mouseY <= y + comp.getHeight() - 2) {
            comp.hover = true;
            comp.mouseEvent(right ? mouseX - width / 2 - x : mouseX - x, mouseY - y /* Make the Y relevant to the component */);

            if (Mouse.isButtonDown(0)) {
                if (!tab.clickStates.computeIfAbsent(comp, ignored -> false)) {
                    comp.onClick(right ? mouseX - width / 2 : mouseX,
                        mouseY - y /* Make the Y relevant to the component */);
                    tab.clickStates.put(comp, true);
                }
            } else if (tab.clickStates.computeIfAbsent(comp, ignored -> false)) {
                tab.clickStates.put(comp, false);
            }
        } else {
            comp.hover = false;
        }

        boolean b = right || parent != null;
        if (b) y += Math.max(comp.getHeight(), prevH);
        right = !right;
        prevH = comp.getHeight();
    }
}
 
Example 9
Source File: RenderTank.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void render(TileEntity tile, double x,
		double y, double z, float f, int damage, float a) {

	IFluidHandler fluidTile = (IFluidHandler)tile;
	FluidStack fluid = fluidTile.getTankProperties()[0].getContents();
	ResourceLocation fluidIcon = new ResourceLocation("advancedrocketry:textures/blocks/fluid/oxygen_flow.png");

	if(fluid != null && fluid.getFluid() != null)
	{
		GL11.glPushMatrix();

		GL11.glTranslatef((float)x, (float)y, (float)z);

		double minU = 0, maxU = 1, minV = 0, maxV = 1;
		TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
		TextureAtlasSprite sprite = map.getTextureExtry(fluid.getFluid().getStill().toString());
		if(sprite != null) {
			minU = sprite.getMinU();
			maxU = sprite.getMaxU();
			minV = sprite.getMinV();
			maxV = sprite.getMaxV();
			GlStateManager.bindTexture(map.getGlTextureId());
		}
		else {
			int color = fluid.getFluid().getColor();
			GL11.glColor4f(((color >>> 16) & 0xFF)/255f, ((color >>> 8) & 0xFF)/255f, ((color& 0xFF)/255f),1f);
			
			bindTexture(fluidIcon);
		}
		

		
		Block block = tile.getBlockType();
		Tessellator tess = Tessellator.getInstance();

		float amt = fluid.amount / (float)fluidTile.getTankProperties()[0].getCapacity();
		
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glDisable(GL11.GL_LIGHTING);
		
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		
		AxisAlignedBB bb = block.getDefaultState().getBoundingBox(tile.getWorld(), tile.getPos());
		
		tess.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
		RenderHelper.renderCubeWithUV(tess.getBuffer(), bb.minX + 0.01, bb.minY + 0.01, bb.minZ + 0.01, bb.maxX - 0.01, bb.maxY*amt - 0.01, bb.maxZ - 0.01, minU, maxU, minV, maxV);
		tess.draw();

		GL11.glEnable(GL11.GL_LIGHTING);
		GL11.glDisable(GL11.GL_BLEND);
		GL11.glPopMatrix();
		GL11.glColor3f(1f, 1f, 1f);
	}
}
 
Example 10
Source File: GuiItemIconDumper.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private BufferedImage screenshot() {
    Framebuffer fb = Minecraft.getMinecraft().getFramebuffer();
    Dimension mcSize = GuiDraw.getDisplayRes();
    Dimension texSize = mcSize;

    if (OpenGlHelper.isFramebufferEnabled()) {
        texSize = new Dimension(fb.framebufferTextureWidth, fb.framebufferTextureHeight);
    }

    int k = texSize.width * texSize.height;
    if (pixelBuffer == null || pixelBuffer.capacity() < k) {
        pixelBuffer = BufferUtils.createIntBuffer(k);
        pixelValues = new int[k];
    }

    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    pixelBuffer.clear();

    if (OpenGlHelper.isFramebufferEnabled()) {
        GlStateManager.bindTexture(fb.framebufferTexture);
        GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
    } else {
        GL11.glReadPixels(0, 0, texSize.width, texSize.height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
    }

    pixelBuffer.get(pixelValues);
    TextureUtil.processPixelValues(pixelValues, texSize.width, texSize.height);

    BufferedImage img = new BufferedImage(mcSize.width, mcSize.height, BufferedImage.TYPE_INT_ARGB);
    if (OpenGlHelper.isFramebufferEnabled()) {
        int yOff = texSize.height - mcSize.height;
        for (int y = 0; y < mcSize.height; ++y) {
            for (int x = 0; x < mcSize.width; ++x) {
                img.setRGB(x, y, pixelValues[(y + yOff) * texSize.width + x]);
            }
        }
    } else {
        img.setRGB(0, 0, texSize.width, height, pixelValues, 0, texSize.width);
    }

    return img;
}
 
Example 11
Source File: WrapperGlStateManager.java    From ClientBase with MIT License 4 votes vote down vote up
public static void bindTexture(int var0) {
    GlStateManager.bindTexture(var0);
}
 
Example 12
Source File: NotificationCenter.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Render this notification
 */
void render() {
    if (ticksLeft <= 0) return;
    if (!Settings.SHOW_INGAME_NOTIFICATION_CENTER) return;
    setDefaultFontRenderer();

    ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());

    // Update percentage -- Called in getX()
    // updatePercentage();
    int x = getX(sr);
    int y = getY(sr);

    int alpha = (int) clamp(percentComplete * 255, 127, 255);

    // Background
    Gui.drawRect(x, y, x + width, y + height, new Color(30, 30, 30, alpha).getRGB());
    GlStateManager.enableBlend();

    // Highlight color
    setHighlightColor(highlightColor); // Anti-NPE
    drawRect(x, y, x + highlightBarWidth, y + height, highlightColor.getRGB() | alpha << 24);
    GlStateManager.enableBlend();

    // Title Text
    fontRenderer.drawString(trimString(String.valueOf(title), width - rightMargins,
        null, true), x + highlightBarWidth + highlightBarMargins, y + topPadding, 0xFFFFFF | alpha << 24);

    // Description text
    if (descriptionColor == null) descriptionColor = new Color(80, 80, 80); // Anti-NPE
    // Don't draw if no lines
    int wrapWidth = getWrapWidth();
    // Trim & split into multiple lines
    List<String> lines = fontRenderer.listFormattedStringToWidth(String.valueOf(description), wrapWidth);
    if (lines.size() > maxDescriptionLines) { // Trim size & last line if overflow
        String nextLine = lines.get(maxDescriptionLines); // The line that would appear after the last one
        lines = lines.subList(0, maxDescriptionLines);
        // Next line is appended to guarantee three ellipsis on the end of the string
        lines.set(lines.size() - 1, trimString(lines.get(lines.size() - 1) + " " + nextLine,
            wrapWidth, null, true));
    }

    // Draw lines
    int currentLine = 0;
    for (String line : lines) {
        fontRenderer.drawString(String.valueOf(line),
            x + highlightBarWidth + highlightBarMargins,
            y + topPadding + fontRenderer.FONT_HEIGHT + lineSpacing + fontRenderer.FONT_HEIGHT * currentLine,
            descriptionColor.getRGB() | alpha << 24);

        if (++currentLine >= maxDescriptionLines) break; // stop if too many lines have gone by
    }

    // Notification Image
    if (img != null) {
        imgScale = (double) (height - topPadding - fontRenderer.FONT_HEIGHT - imgTopMargins) / imgSize;

        if (imgScale * imgSize > (double) width / 4) {
            imgScale = ((double) width / 4) / imgSize; // Limit to 25% of width
        }

        GlStateManager.color(1, 1, 1, 1);
        GlStateManager.scale(imgScale, imgScale, imgScale);
        GlStateManager.bindTexture(img.getGlTextureId());
        GlStateManager.enableTexture2D();
        drawTexturedModalRect(
            (float) ((x + width - rightMargins) / imgScale - imgSize),
            (float) (y / imgScale + (((height + fontRenderer.FONT_HEIGHT) / imgScale) - imgSize) / 2),
            0,
            0,
            imgSize,
            imgSize);
        GlStateManager.scale(1 / imgScale, 1 / imgScale, 1 / imgScale);
    } else {
        imgScale = 0;
    }
}
 
Example 13
Source File: DisplayElementConfig.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    ScaledResolution current = ResolutionUtil.current();
    mouseLock = mouseLock && Mouse.isButtonDown(0);
    drawRect(0, 0, current.getScaledWidth(), current.getScaledHeight(), new Color(0, 0, 0, 150).getRGB());
    super.drawScreen(mouseX, mouseY, partialTicks);

    ElementRenderer.startDrawing(element);
    element.renderEditView();
    ElementRenderer.endDrawing(element);
    int left = posX(1);
    int top = posY(2);
    int right = posX(2);
    int size = right - left;

    if (element.isRGB()) {
        int start_y = Math.max((int) (current.getScaledHeight_double() * .1) - 20, 5) + 22 * 8 + 25;
        int left1 = current.getScaledWidth() / 2 - 100;
        int right1 = current.getScaledWidth() / 2 + 100;
        Gui.drawRect(left1, start_y, right1, right1 - left1 + 200, element.getColor());
    }

    if (!element.isColorPallet()) return;

    apply(mouseX, mouseY);
    GlStateManager.bindTexture(texture.getGlTextureId());
    GlStateManager.enableTexture2D();
    GL11.glPushMatrix();
    GL11.glTranslatef(left, top, 0);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);//
    GlStateManager.scale(size / 285F, size / 285F, 0);
    drawTexturedModalRect(0, 0, 0, 0, 256, 256);

    if (texture2 != null) {
        GlStateManager.bindTexture(texture2.getGlTextureId());
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glTranslatef(256 + 15, 0, 0);
        drawTexturedModalRect(0, 0, 0, 0, 15, 256);
    }

    GlStateManager.scale(285F / size, 285F / size, 0);
    GL11.glPopMatrix();
    if (lastX != 0 && lastY != 0) drawCircle(lastX, lastY);
}
 
Example 14
Source File: HyperiumFontRenderer.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int drawString(String text, float x, float y, int color) {
    if (text == null) return 0;

    ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());

    try {
        if (resolution.getScaleFactor() != prevScaleFactor) {
            prevScaleFactor = resolution.getScaleFactor();
            unicodeFont = new UnicodeFont(getFontByName(name).deriveFont(size * prevScaleFactor / 2));
            unicodeFont.addAsciiGlyphs();
            unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE));
            unicodeFont.loadGlyphs();
        }
    } catch (FontFormatException | IOException | SlickException e) {
        e.printStackTrace();
    }

    this.antiAliasingFactor = resolution.getScaleFactor();

    GL11.glPushMatrix();
    GlStateManager.scale(1 / antiAliasingFactor, 1 / antiAliasingFactor, 1 / antiAliasingFactor);
    x *= antiAliasingFactor;
    y *= antiAliasingFactor;
    float originalX = x;
    float red = (float) (color >> 16 & 255) / 255.0F;
    float green = (float) (color >> 8 & 255) / 255.0F;
    float blue = (float) (color & 255) / 255.0F;
    float alpha = (float) (color >> 24 & 255) / 255.0F;
    GlStateManager.color(red, green, blue, alpha);

    int currentColor = color;

    char[] characters = text.toCharArray();

    GlStateManager.disableLighting();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    String[] parts = COLOR_CODE_PATTERN.split(text);
    int index = 0;
    for (String s : parts) {
        for (String s2 : s.split("\n")) {
            for (String s3 : s2.split("\r")) {

                unicodeFont.drawString(x, y, s3, new org.newdawn.slick.Color(currentColor));
                x += unicodeFont.getWidth(s3);

                index += s3.length();
                if (index  < characters.length && characters[index ] == '\r') {
                    x = originalX;
                    index++;
                }
            }
            if (index < characters.length && characters[index] == '\n') {
                x = originalX;
                y += getHeight(s2) * 2;
                index++;
            }
        }
        if (index < characters.length) {
            char colorCode = characters[index];
            if (colorCode == 'ยง') {
                char colorChar = characters[index + 1];
                int codeIndex = ("0123456789" +
                    "abcdef").indexOf(colorChar);
                if (codeIndex < 0) {
                    if (colorChar == 'r') {
                        currentColor = color;
                    }
                } else {
                    currentColor = colorCodes[codeIndex];
                }
                index += 2;
            }
        }
    }

    GlStateManager.color(1F, 1F, 1F, 1F);
    GlStateManager.bindTexture(0);
    GlStateManager.popMatrix();
    return (int) x;
}
 
Example 15
Source File: HyperiumScreenshotHelper.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static IChatComponent saveScreenshot(int width, int height, Framebuffer buffer, IntBuffer pixelBuffer, int[] pixelValues) {
    final File file1 = new File(Minecraft.getMinecraft().mcDataDir, "screenshots");
    file1.mkdir();

    if (OpenGlHelper.isFramebufferEnabled()) {
        width = buffer.framebufferTextureWidth;
        height = buffer.framebufferTextureHeight;
    }

    final int i = width * height;

    if (pixelBuffer == null || pixelBuffer.capacity() < i) {
        pixelBuffer = BufferUtils.createIntBuffer(i);
        pixelValues = new int[i];
    }

    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    pixelBuffer.clear();

    if (OpenGlHelper.isFramebufferEnabled()) {
        GlStateManager.bindTexture(buffer.framebufferTexture);
        GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
    } else {
        GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
    }

    boolean upload = true;
    pixelBuffer.get(pixelValues);

    if (!Settings.DEFAULT_UPLOAD_SS) {
        HyperiumBind uploadBind = Hyperium.INSTANCE.getHandlers().getKeybindHandler().getBinding("Upload Screenshot");
        int keyCode = uploadBind.getKeyCode();
        upload = keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode);
    }

    new Thread(new AsyncScreenshotSaver(width, height, pixelValues, Minecraft.getMinecraft().getFramebuffer(),
        new File(Minecraft.getMinecraft().mcDataDir, "screenshots"), upload)).start();
    if (!upload) {
        return Settings.HYPERIUM_CHAT_PREFIX ? new ChatComponentText(ChatColor.RED + "[Hyperium] " + ChatColor.WHITE + "Capturing...") :
            new ChatComponentText(ChatColor.WHITE + "Capturing...");
    }
    return Settings.HYPERIUM_CHAT_PREFIX ? new ChatComponentText(ChatColor.RED + "[Hyperium] " + ChatColor.WHITE + "Uploading...") :
        new ChatComponentText(ChatColor.WHITE + "Uploading...");
}
 
Example 16
Source File: GlyphPage.java    From ClientBase with MIT License 4 votes vote down vote up
public void unbindTexture() {
    GlStateManager.bindTexture(0);
}
 
Example 17
Source File: GlyphPage.java    From ClientBase with MIT License 4 votes vote down vote up
public void bindTexture() {
    GlStateManager.bindTexture(loadedTexture.getGlTextureId());
}