List of usage examples for org.lwjgl.opengl GL11 glReadPixels
public static void glReadPixels(@NativeType("GLint") int x, @NativeType("GLint") int y, @NativeType("GLsizei") int width, @NativeType("GLsizei") int height, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @NativeType("void *") float[] pixels)
From source file:loon.core.graphics.opengl.LWjglGL10.java
License:Apache License
public final void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) { GL11.glReadPixels(x, y, width, height, format, type, (ByteBuffer) pixels); } else if (pixels instanceof ShortBuffer) { GL11.glReadPixels(x, y, width, height, format, type, (ShortBuffer) pixels); } else if (pixels instanceof IntBuffer) { GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer) pixels); } else if (pixels instanceof FloatBuffer) { GL11.glReadPixels(x, y, width, height, format, type, (FloatBuffer) pixels); } else {/*from w w w . j a v a 2 s.co m*/ throw new RuntimeException("Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer or FloatBuffer instead. Blame LWJGL"); } }
From source file:minebot.ui.Screenshot.java
public static void screenshot() { if (currPixVal != null) { System.out.println("Skipping"); return;/*from w w w . j a v a2 s . c om*/ } int width = Minecraft.theMinecraft.displayWidth; int height = Minecraft.theMinecraft.displayHeight; int i = width * height; final IntBuffer pixelBuffer = getBuf(i); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer); new Thread() { @Override public void run() { int[] pixelValues = getInt(i); pixelBuffer.get(pixelValues); TextureUtil.processPixelValues(pixelValues, width, height); /*BufferedImage bufferedimage; bufferedimage = new BufferedImage(width, height, 1); bufferedimage.setRGB(0, 0, width, height, pixelValues, 0, width);*/ pushBuf(pixelBuffer); boolean hasSockets; synchronized (socketsLock) { hasSockets = !sockets.isEmpty(); } if (!hasSockets) { pushInt(pixelValues); return; } synchronized (currPixLock) { if (currPixVal != null) { pushInt(currPixVal); } currPixVal = pixelValues; currWidth = width; currHeight = height; } } }.start(); }
From source file:mss.View.java
License:Open Source License
private void saveScreenshot() { final File f = new File(View.class.getProtectionDomain().getCodeSource().getLocation().getPath()); GL11.glReadBuffer(GL11.GL_FRONT);// ww w .j a v a 2s . co m int width = Display.getWidth(); int height = Display.getHeight(); ByteBuffer byteBuffer = BufferUtils.createByteBuffer(width * height * 4); GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, byteBuffer); ScreenshotSaver saver = new ScreenshotSaver(byteBuffer, f.getParent(), width, height); saver.start(); }
From source file:mwisbest.openbase.opengl.UtilsGL.java
License:Open Source License
public static void takeScreenshot(String filename) { GL11.glReadBuffer(GL11.GL_FRONT);//from w w w . j a v a2s . c om int width = Display.getDisplayMode().getWidth(); int height = Display.getDisplayMode().getHeight(); int bpp = 4; ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp); GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); File file = new File(filename); 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); } } try { ImageIO.write(image, "PNG", file); } catch (IOException e) { e.printStackTrace(); } }
From source file:opengl.Player.java
public void CheckDown() { if (Jumping == false) { FloatBuffer MatrixData = BufferUtils.createFloatBuffer(16); float[] Matrix = new float[16]; MatrixData.rewind();//from w ww . j a va2s .co m GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, MatrixData); MatrixData.get(Matrix); for (int www = 0; Matrix.length > www; www++) { //System.out.print(Matrix[www] + " "); } //System.out.println(); float Offset = 0; boolean z = false; FloatBuffer DATA = BufferUtils.createFloatBuffer(4); for (Offset = 0.0f; ScaleX >= Offset; Offset = Offset + 2.0f / 1920.0f) { DATA.rewind(); GL11.glReadPixels((int) ((x + 1.0f + Matrix[12] + Offset) * 960.0f), (int) (((y + 1.0f - (2.0f / 1080.0f))) * 540.0f - 20.0f), 1, 1, GL11.GL_RGBA, GL11.GL_FLOAT, DATA); // 2/1920 // 2/1080 //GL11.glReadPixels((int) ((-0.6f + 1.0f + Offset) * 960.0f), (int) (((-0.95f + 1.0f - (2.0f / 1080.0f))) * 540.0f ), 1, 1, GL11.GL_RGBA, GL11.GL_FLOAT, DATA); if (DATA.get() == 0.0f) { z = true; } else { Time = 0; HowFarUp = 0; z = false; break; } } if (z == true) { Time = Time + 1.0f / 60.0f; y = y - (2.0f / 1080.0f) * (Gravity * Time); } } else { Time = Time + 1.0f / 60.0f; v = (Gravity * Time - InitialJumpingV) * -1; HowFarUp++; if (v > 0) { y = y + (2.0f / 1080.0f) * v; } else { //HowFarUp = 0; Time = 0; Jumping = false; } } }
From source file:org.eclipse.swt.snippets.Snippet341.java
License:Open Source License
static void capture(GLCanvas glCanvas) { final int PAD = 4; Display display = glCanvas.getDisplay(); Rectangle bounds = glCanvas.getBounds(); int size = bounds.width * PAD * bounds.height; ByteBuffer buffer = ByteBuffer.allocateDirect(size); GL11.glReadPixels(0, 0, bounds.width, bounds.height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); byte[] bytes = new byte[size]; buffer.get(bytes);/*from w w w . ja va2s . c o m*/ /* * In OpenGL (0,0) is at the bottom-left corner, and y values ascend in the upward * direction. This is opposite to SWT which defines (0,0) to be at the top-left * corner with y values ascendingin the downwards direction. Re-order the OpenGL- * provided bytes to SWT's expected order so that the Image will not appear inverted. */ byte[] temp = new byte[bytes.length]; for (int i = 0; i < bytes.length; i += bounds.width * PAD) { System.arraycopy(bytes, bytes.length - i - bounds.width * PAD, temp, i, bounds.width * PAD); } bytes = temp; ImageData data = new ImageData(bounds.width, bounds.height, 32, new PaletteData(0xFF000000, 0xFF0000, 0xFF00), PAD, bytes); final Image image = new Image(display, data); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); Canvas canvas = new Canvas(shell, SWT.NONE); canvas.setLayoutData(new GridData(bounds.width, bounds.height)); canvas.addListener(SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { event.gc.drawImage(image, 0, 0); } }); shell.pack(); shell.open(); shell.addListener(SWT.Dispose, new Listener() { @Override public void handleEvent(Event event) { image.dispose(); } }); }
From source file:org.fenggui.binding.render.lwjgl.LWJGLOpenGL.java
License:Open Source License
public void readPixels(int x, int y, int width, int height, ByteBuffer bgr) { GL11.glReadPixels(x, y, width, height, GL12.GL_BGR, GL11.GL_UNSIGNED_BYTE, bgr); }
From source file:org.free.jake2.render.lwjgl.Misc.java
License:Open Source License
void GL_ScreenShot_f() { StringBuilder sb = new StringBuilder(FileSystem.Gamedir() + "/scrshot/jake00.tga"); FileSystem.CreatePath(sb.toString()); File file = new File(sb.toString()); // find a valid file name int i = 0;/* www . j a v a 2 s. co m*/ int offset = sb.length() - 6; while (file.exists() && i++ < 100) { sb.setCharAt(offset, (char) ((i / 10) + '0')); sb.setCharAt(offset + 1, (char) ((i % 10) + '0')); file = new File(sb.toString()); } if (i == 100) { VID.Printf(Defines.PRINT_ALL, "Clean up your screenshots\n"); return; } try { RandomAccessFile out = new RandomAccessFile(file, "rw"); FileChannel ch = out.getChannel(); int fileLength = TGA_HEADER_SIZE + vid.width * vid.height * 3; out.setLength(fileLength); MappedByteBuffer image = ch.map(FileChannel.MapMode.READ_WRITE, 0, fileLength); // write the TGA header image.put(0, (byte) 0).put(1, (byte) 0); image.put(2, (byte) 2); // uncompressed type image.put(12, (byte) (vid.width & 0xFF)); // vid.width image.put(13, (byte) (vid.width >> 8)); // vid.width image.put(14, (byte) (vid.height & 0xFF)); // vid.height image.put(15, (byte) (vid.height >> 8)); // vid.height image.put(16, (byte) 24); // pixel size // go to image data position image.position(TGA_HEADER_SIZE); // change pixel alignment for reading if (vid.width % 4 != 0) { GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); } // OpenGL 1.2+ supports the GL_BGR color format // check the GL_VERSION to use the TARGA BGR order if possible // e.g.: 1.5.2 NVIDIA 66.29 if (gl_config.getOpenGLVersion() >= 1.2f) { // read the BGR values into the image buffer GL11.glReadPixels(0, 0, vid.width, vid.height, GL12.GL_BGR, GL11.GL_UNSIGNED_BYTE, image); } else { // read the RGB values into the image buffer GL11.glReadPixels(0, 0, vid.width, vid.height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, image); // flip RGB to BGR byte tmp; for (i = TGA_HEADER_SIZE; i < fileLength; i += 3) { tmp = image.get(i); image.put(i, image.get(i + 2)); image.put(i + 2, tmp); } } // reset to default alignment GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 4); // close the file channel ch.close(); } catch (IOException e) { VID.Printf(Defines.PRINT_ALL, e.getMessage() + '\n'); } VID.Printf(Defines.PRINT_ALL, "Wrote " + file + '\n'); }
From source file:org.jge.util.LWJGLHandler.java
License:Open Source License
public static BufferedImage takeScreenshot() { int k = Display.getWidth() * Display.getHeight(); if (screenshotBuffer == null || screenshotBuffer.capacity() < k) { screenshotBuffer = BufferUtils.createIntBuffer(k); screenshotBufferArray = new int[k]; }/*from www . ja v a 2s .c om*/ GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); screenshotBuffer.clear(); GL11.glReadPixels(0, 0, Display.getWidth(), Display.getHeight(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, screenshotBuffer); screenshotBuffer.get(screenshotBufferArray); int[] aint1 = new int[Display.getWidth()]; int j = Display.getHeight() / 2; for (int l = 0; l < j; ++l) { System.arraycopy(screenshotBufferArray, l * Display.getWidth(), aint1, 0, Display.getWidth()); System.arraycopy(screenshotBufferArray, (Display.getHeight() - 1 - l) * Display.getWidth(), screenshotBufferArray, l * Display.getWidth(), Display.getWidth()); System.arraycopy(aint1, 0, screenshotBufferArray, (Display.getHeight() - 1 - l) * Display.getWidth(), Display.getWidth()); } BufferedImage bufferedimage = new BufferedImage(Display.getWidth(), Display.getHeight(), BufferedImage.TYPE_INT_RGB); for (int i = 0; i < screenshotBufferArray.length; i++) { Color c = ImageUtils.getColor(screenshotBufferArray[i]); screenshotBufferArray[i] = new Color(c.getBlue(), c.getGreen(), c.getRed()).getRGB(); } bufferedimage.setRGB(0, 0, Display.getWidth(), Display.getHeight(), screenshotBufferArray, 0, Display.getWidth()); return bufferedimage; }
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public void readPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) GL11.glReadPixels(x, y, width, height, format, type, (ByteBuffer) pixels); else if (pixels instanceof ShortBuffer) GL11.glReadPixels(x, y, width, height, format, type, (ShortBuffer) pixels); else if (pixels instanceof IntBuffer) GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer) pixels); else if (pixels instanceof FloatBuffer) GL11.glReadPixels(x, y, width, height, format, type, (FloatBuffer) pixels); else//from ww w . j a va 2 s.c om throw new GdxRuntimeException("Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer or FloatBuffer instead. Blame LWJGL"); }