List of usage examples for org.lwjgl.opengl GL11 glGetTexImage
public static void glGetTexImage(@NativeType("GLenum") int tex, @NativeType("GLint") int level, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @NativeType("void *") double[] pixels)
From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java
License:Open Source License
@Override public void getTexImage(int level, int format, int type, Buffer buffer) { if (buffer instanceof ByteBuffer) { ByteBuffer directBuffer = allocateDirectBuffer((ByteBuffer) buffer); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, textureFormatToGL[format], textureTypeToGL[type], (ByteBuffer) buffer); copyBuffer((ByteBuffer) buffer, directBuffer); } else if (buffer instanceof IntBuffer) { IntBuffer directBuffer = allocateDirectBuffer((IntBuffer) buffer); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, textureFormatToGL[format], textureTypeToGL[type], directBuffer);/* w w w . ja v a 2 s . c o m*/ copyBuffer((IntBuffer) buffer, directBuffer); } else if (buffer instanceof ShortBuffer) { ShortBuffer directBuffer = allocateDirectBuffer((ShortBuffer) buffer); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, textureFormatToGL[format], textureTypeToGL[type], (ShortBuffer) buffer); copyBuffer((ShortBuffer) buffer, directBuffer); } else if (buffer instanceof FloatBuffer) { FloatBuffer directBuffer = allocateDirectBuffer((FloatBuffer) buffer); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, textureFormatToGL[format], textureTypeToGL[type], (FloatBuffer) buffer); copyBuffer((FloatBuffer) buffer, directBuffer); } else { throw new IllegalArgumentException(); } }
From source file:mwisbest.openbase.opengl.TextureImplementation.java
License:Open Source License
@Override public byte[] getTextureData() { ByteBuffer buffer = BufferUtils .createByteBuffer(this.format.getColorComponents() * this.texWidth * this.texHeight); this.bind();/* w w w .j a v a 2s . c o m*/ GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, this.format.getOGLType(), GL11.GL_UNSIGNED_BYTE, buffer); byte[] data = new byte[buffer.limit()]; buffer.get(data); buffer.clear(); return data; }
From source file:net.neilcsmith.praxis.video.opengl.internal.GLRenderer.java
License:Apache License
void syncTextureToPixels(GLSurfaceData data) { LOGGER.fine("Copying texture to pixels"); if (data.texture == target) { LOGGER.fine("Texture is current render target"); flush();/*from w ww .j ava 2s . c o m*/ } int tWidth = data.texture.getWidth(); int size = tWidth * data.texture.getHeight(); if (scratchBuffer == null || scratchBuffer.capacity() < size) { scratchBuffer = BufferUtils.createIntBuffer(size); } scratchBuffer.rewind(); data.texture.bind(); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, scratchBuffer); scratchBuffer.rewind(); int offset = 0; for (int y = 0; y < data.height; y++) { scratchBuffer.position(offset); scratchBuffer.get(data.pixels, y * data.width, data.width); offset += tWidth; } }
From source file:org.terasology.rendering.opengl.DefaultRenderingProcess.java
License:Apache License
public void saveScreenshot() { if (!takeScreenshot) { return;/*from w ww.j a v a 2s. c o m*/ } final FBO fboSceneFinal = getFBO("sceneFinal"); if (fboSceneFinal == null) { return; } final ByteBuffer buffer = BufferUtils.createByteBuffer(fboSceneFinal.width * fboSceneFinal.height * 4); fboSceneFinal.bindTexture(); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); fboSceneFinal.unbindTexture(); Runnable r = new Runnable() { @Override public void run() { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss"); final String fileName = "Terasology-" + sdf.format(cal.getTime()) + "-" + fboSceneFinal.width + "x" + fboSceneFinal.height + ".png"; Path path = PathManager.getInstance().getScreenshotPath().resolve(fileName); BufferedImage image = new BufferedImage(fboSceneFinal.width, fboSceneFinal.height, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < fboSceneFinal.width; x++) { for (int y = 0; y < fboSceneFinal.height; y++) { int i = (x + fboSceneFinal.width * y) * 4; int r = buffer.get(i) & 0xFF; int g = buffer.get(i + 1) & 0xFF; int b = buffer.get(i + 2) & 0xFF; image.setRGB(x, fboSceneFinal.height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b); } } try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(path))) { ImageIO.write(image, "png", out); logger.info("Screenshot '" + fileName + "' saved! "); } catch (IOException e) { logger.warn("Failed to save screenshot!", e); } } }; CoreRegistry.get(GameEngine.class).submitTask("Write screenshot", r); takeScreenshot = false; overwriteRtWidth = 0; overwriteRtWidth = 0; createOrUpdateFullscreenFbos(); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
/** * Returns the content of the color buffer from GPU memory as a ByteBuffer. * @return a ByteBuffer or null/*from w w w .j av a2s. c o m*/ */ public ByteBuffer getColorBufferRawData() { ByteBuffer buffer = BufferUtils.createByteBuffer(this.width() * this.height() * 4); this.bindTexture(); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); FBO.unbindTexture(); return buffer; }
From source file:org.terasology.rendering.opengl.FrameBuffersManager.java
License:Apache License
/** * Returns the content of the color buffer of the FBO "sceneFinal", from GPU memory as a ByteBuffer. * If the FBO "sceneFinal" is unavailable, returns null. * * @return a ByteBuffer or null/*from w w w. j a v a 2 s. c o m*/ */ public ByteBuffer getSceneFinalRawData() { FBO fboSceneFinal = getFBO("sceneFinal"); if (fboSceneFinal == null) { logger.error("FBO sceneFinal is unavailable: cannot return data from it."); return null; } ByteBuffer buffer = BufferUtils.createByteBuffer(fboSceneFinal.width() * fboSceneFinal.height() * 4); fboSceneFinal.bindTexture(); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); FBO.unbindTexture(); return buffer; }
From source file:org.terasology.rendering.opengl.LwjglRenderingProcess.java
License:Apache License
public void saveScreenshot() { if (!takeScreenshot) { return;//from ww w. j av a 2 s . c o m } final FBO fboSceneFinal = getFBO("sceneFinal"); if (fboSceneFinal == null) { return; } final ByteBuffer buffer = BufferUtils.createByteBuffer(fboSceneFinal.width() * fboSceneFinal.height() * 4); fboSceneFinal.bindTexture(); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); fboSceneFinal.unbindTexture(); Runnable task = new Runnable() { @Override public void run() { SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss"); final String format = renderingConfig.getScreenshotFormat().toString(); final String fileName = "Terasology-" + sdf.format(new Date()) + "-" + fboSceneFinal.width() + "x" + fboSceneFinal.height() + "." + format; Path path = PathManager.getInstance().getScreenshotPath().resolve(fileName); BufferedImage image = new BufferedImage(fboSceneFinal.width(), fboSceneFinal.height(), BufferedImage.TYPE_INT_RGB); for (int x = 0; x < fboSceneFinal.width(); x++) { for (int y = 0; y < fboSceneFinal.height(); y++) { int i = (x + fboSceneFinal.width() * y) * 4; int r = buffer.get(i) & 0xFF; int g = buffer.get(i + 1) & 0xFF; int b = buffer.get(i + 2) & 0xFF; image.setRGB(x, fboSceneFinal.height() - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b); } } try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(path))) { ImageIO.write(image, format, out); logger.info("Screenshot '" + fileName + "' saved! "); } catch (IOException e) { logger.warn("Failed to save screenshot!", e); } } }; CoreRegistry.get(GameEngine.class).submitTask("Write screenshot", task); takeScreenshot = false; overwriteRtWidth = 0; overwriteRtHeight = 0; createOrUpdateFullscreenFbos(); }
From source file:org.terasology.rendering.renderingProcesses.DefaultRenderingProcess.java
License:Apache License
public void saveScreenshot() { if (!takeScreenshot) { return;/*www . jav a 2 s .co m*/ } final FBO fboSceneFinal = getFBO("sceneFinal"); if (fboSceneFinal == null) { return; } final ByteBuffer buffer = BufferUtils.createByteBuffer(fboSceneFinal.width * fboSceneFinal.height * 4); fboSceneFinal.bindTexture(); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); fboSceneFinal.unbindTexture(); Runnable r = new Runnable() { @Override public void run() { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss"); final String fileName = "Terasology-" + sdf.format(cal.getTime()) + "-" + fboSceneFinal.width + "x" + fboSceneFinal.height + ".png"; File file = new File(PathManager.getInstance().getScreenshotPath(), fileName); BufferedImage image = new BufferedImage(fboSceneFinal.width, fboSceneFinal.height, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < fboSceneFinal.width; x++) for (int y = 0; y < fboSceneFinal.height; y++) { int i = (x + fboSceneFinal.width * y) * 4; int r = buffer.get(i) & 0xFF; int g = buffer.get(i + 1) & 0xFF; int b = buffer.get(i + 2) & 0xFF; image.setRGB(x, fboSceneFinal.height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b); } try { ImageIO.write(image, "png", file); logger.info("Screenshot '" + fileName + "' saved! "); } catch (IOException e) { logger.warn("Could not save screenshot!", e); } } }; CoreRegistry.get(GameEngine.class).submitTask("Write screenshot", r); takeScreenshot = false; overwriteRtWidth = 0; overwriteRtWidth = 0; createOrUpdateFullscreenFbos(); }
From source file:tk.ivybits.engine.gl.GL.java
License:Open Source License
public static void glGetTexImage(int a, int b, int c, int d, ByteBuffer e) { GL11.glGetTexImage(a, b, c, d, e); }
From source file:tk.ivybits.engine.gl.GL.java
License:Open Source License
public static void glGetTexImage(int a, int b, int c, int d, FloatBuffer e) { GL11.glGetTexImage(a, b, c, d, e); }