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

The following examples show how to use org.lwjgl.opengl.GL11#glReadBuffer() . 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: Recorder.java    From Gaalop with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Make a screenshot from the current LWJGL Display
 * Code from pc
 */
public void makeScreenshot() {
    curTime = System.currentTimeMillis();
   
    ByteBuffer screenBuffer = ByteBuffer.allocateDirect(Display.getDisplayMode().getWidth() * Display.getDisplayMode().getHeight() * 3);
    
    try {
            GL11.glReadBuffer(GL11.GL_BACK);
            GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
            GL11.glReadPixels(0, 0, Display.getDisplayMode().getWidth(),
                            Display.getDisplayMode().getHeight(), GL11.GL_RGB,
                            GL11.GL_UNSIGNED_BYTE, screenBuffer);
            
            long delay = (lastTime == -1) ? 0: curTime-lastTime;
            lastTime = curTime;
            thread.addFrame(screenBuffer, delay);
            
    } catch (Exception e) {
            System.out.println("Streaming exception.");
            e.printStackTrace();
    }
}
 
Example 2
Source File: PbufferRenderer.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
PbufferRenderer(int width, int height, PixelFormat format, boolean use_copyteximage, OffscreenRendererFactory factory) throws LWJGLException {
	super(width, height, use_copyteximage);
	this.factory = factory;
	pbuffer = new Pbuffer(width, height, format, null, null);
	GLStateStack state_stack = new GLStateStack();
	pbuffer.makeCurrent();
	GLStateStack.setCurrent(state_stack);
	try {
		pbuffer.makeCurrent();
		Renderer.dumpWindowInfo();
		init();
		if (!GLUtils.getGLBoolean(GL11.GL_DOUBLEBUFFER)) {
			GL11.glReadBuffer(GL11.GL_FRONT);
			GL11.glDrawBuffer(GL11.GL_FRONT);
		}
	} catch (LWJGLException e) {
		pbuffer.destroy();
		throw e;
	}
}
 
Example 3
Source File: Fbo.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
/**
 * Copy the contents of a colour attachment of this FBO to the screen.
 * 
 * @param colourIndex
 *            - The index of the colour buffer that should be blitted.
 */
public void blitToScreen(int colourIndex) {
	GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0);
	GL11.glDrawBuffer(GL11.GL_BACK);
	GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, fboId);
	GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0 + colourIndex);
	GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, Display.getWidth(), Display.getHeight(),
			GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}
 
Example 4
Source File: Fbo.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
/**
 * Copy the contents of this FBO to another FBO. This can be used to resolve
 * multisampled FBOs.
 * 
 * @param srcColourIndex
 *            - Index of the colour buffer in this (the source) FBO.
 * @param target
 *            - The target FBO.
 * @param targetColourIndex
 *            - The index of the target colour buffer in the target FBO.
 */
public void blitToFbo(int srcColourIndex, Fbo target, int targetColourIndex) {
	GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, target.fboId);
	GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0 + targetColourIndex);

	GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, fboId);
	GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0 + srcColourIndex);

	int bufferBit = depthAttachment != null && target.depthAttachment != null
			? GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT : GL11.GL_COLOR_BUFFER_BIT;
	GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, target.width, target.height, bufferBit, GL11.GL_NEAREST);
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}
 
Example 5
Source File: Configuration.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @author http://wiki.lwjgl.org/index.php?title=Taking_Screen_Shots
 */
public void takeScreenShot() {
	// TODO: get a decent place for this
	// create the screenshot directory
	if (!screenshotDir.isDirectory() && !screenshotDir.mkdir()) {
		bubNotifs.sendf(
			BUB_RED,
			"Failed to create screenshot directory at '%s'.",
			screenshotDir.getAbsolutePath()
		);
		return;
	}

	// create file name
	SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss");
	final String fileName = String.format("screenshot_%s.%s", date.format(new Date()), OPTION_SCREENSHOT_FORMAT.getValueString().toLowerCase());
	final File file = new File(screenshotDir, fileName);

	SoundController.playSound(SoundEffect.SHUTTER);

	// copy the screen to file
	final int width = Display.getWidth();
	final int height = Display.getHeight();
	final int bpp = 3;  // assuming a 32-bit display with a byte each for red, green, blue, and alpha
	final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
	GL11.glReadBuffer(GL11.GL_FRONT);
	GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
	GL11.glReadPixels(0, 0, width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, buffer);
	new Thread() {
		@Override
		public void run() {
			try {
				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)) * bpp;
						int r = buffer.get(i) & 0xFF;
						int g = buffer.get(i + 1) & 0xFF;
						int b = buffer.get(i + 2) & 0xFF;
						image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
					}
				}
				ImageIO.write(image, OPTION_SCREENSHOT_FORMAT.getValueString().toLowerCase(), file);
				bubNotifs.send(BUB_PURPLE, "Created " + fileName);
			} catch (Exception e) {
				Log.error("Could not take screenshot", e);
				bubNotifs.send(
					BUB_PURPLE,
					"Failed to take a screenshot. See log file for details"
				);
			}
		}
	}.start();
}
 
Example 6
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Bind to the FBO created
 */
private void bind() {
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, FBO);
	GL11.glReadBuffer(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT);
}
 
Example 7
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Unbind from the FBO created
 */
private void unbind() {
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
	GL11.glReadBuffer(GL11.GL_BACK); 
}