Java Code Examples for org.lwjgl.opengl.GL11#glGetTexImage()

The following examples show how to use org.lwjgl.opengl.GL11#glGetTexImage() . 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: 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 2
Source File: ClientDynamicTexture.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
/**
 * 
 * @param x x location of the pixel
 * @param y y location of the pixel
 * @param color color in RGBA8
 */
public void setPixel(int x, int y, int color) {
	
	ByteBuffer buffer = BufferUtils.createByteBuffer(image.getHeight() * image.getWidth() * BYTES_PER_PIXEL);;
	
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId());
	GL11.glGetTexImage(GL11.GL_TEXTURE_2D,0 , GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
	buffer.putInt(x + (y * image.getHeight()), color);
	
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
}
 
Example 3
Source File: GLUtils.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public static void saveTexture(int mipmap_level, String filename) {
		GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, mipmap_level, GL11.GL_TEXTURE_WIDTH, int_buf);
		int width = int_buf.get(0);
		GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, mipmap_level, GL11.GL_TEXTURE_HEIGHT, int_buf);
		int height = int_buf.get(0);
		GLImage pixel_data = new GLIntImage(width, height, GL11.GL_RGBA);
		GL11.glGetTexImage(GL11.GL_TEXTURE_2D, mipmap_level, pixel_data.getGLFormat(), pixel_data.getGLType(), pixel_data.getPixels());
//		swizzleColors(pixel_data.getPixels());
		com.oddlabs.util.Utils.flip(pixel_data.getPixels(), width*4, height);
		pixel_data.saveAsPNG(filename);
		System.gc();
	}
 
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: Texture.java    From mapwriter with MIT License 5 votes vote down vote up
private synchronized void getPixelsFromExistingTexture() {
	try {
		this.bind();
		this.pixelBuf.clear();
		GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, this.pixelBuf);
		// getTexImage does not seem to advance the buffer position, so flip does not work here
		// this.pixelBuf.flip()
		this.pixelBuf.limit(this.w * this.h);
	} catch (NullPointerException e) {
		MwUtil.log("MwTexture.getPixels: null pointer exception (texture %d)", this.id);
	}
}
 
Example 6
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 7
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 8
Source File: ImmediateModeOGLRenderer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.opengl.renderer.SGL#glGetTexImage(int, int, int, int, java.nio.ByteBuffer)
 */
public void glGetTexImage(int target, int level, int format, int type, ByteBuffer pixels) {
	GL11.glGetTexImage(target, level, format, type, pixels);
}