本文整理汇总了Java中com.jogamp.opengl.GL2.glReadPixels方法的典型用法代码示例。如果您正苦于以下问题:Java GL2.glReadPixels方法的具体用法?Java GL2.glReadPixels怎么用?Java GL2.glReadPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jogamp.opengl.GL2
的用法示例。
在下文中一共展示了GL2.glReadPixels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toImage
import com.jogamp.opengl.GL2; //导入方法依赖的package包/类
/**
* Turns gl to BufferedImage with fixed format
*
* @param gl
* @param w
* @param h
* @return
*/
protected BufferedImage toImage(GL2 gl, int w, int h) {
gl.glReadBuffer(GL.GL_FRONT); // or GL.GL_BACK
ByteBuffer glBB = Buffers.newDirectByteBuffer(4 * w * h);
gl.glReadPixels(0, 0, w, h, GL2.GL_BGRA, GL.GL_BYTE, glBB);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int b = 2 * glBB.get();
int g = 2 * glBB.get();
int r = 2 * glBB.get();
int a = glBB.get(); // not using
bd[(h - y - 1) * w + x] = (b << 16) | (g << 8) | r | 0xFF000000;
}
}
return bi;
}
示例2: grabImage
import com.jogamp.opengl.GL2; //导入方法依赖的package包/类
void grabImage(final GLAutoDrawable d) {
final GL2 gl = d.getGL().getGL2();
final int width = d.getSurfaceWidth();
final int height = d.getSurfaceHeight();
// Allocate a buffer for the pixels
final ByteBuffer rgbData = Buffers.newDirectByteBuffer(width * height * 3);
// Set up the OpenGL state.
gl.glReadBuffer(GL.GL_FRONT);
gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
// Read the pixels into the ByteBuffer
gl.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, rgbData);
// Allocate space for the converted pixels
final int[] pixelInts = new int[width * height];
// Convert RGB bytes to ARGB ints with no transparency. Flip
// imageOpenGL vertically by reading the rows of pixels in the byte
// buffer in reverse - (0,0) is at bottom left in OpenGL.
int p = width * height * 3; // Points to first byte (red) in each row.
int q; // Index into ByteBuffer
int i = 0; // Index into target int[]
final int bytesPerRow = width * 3; // Number of bytes in each row
for (int row = height - 1; row >= 0; row--) {
p = row * bytesPerRow;
q = p;
for (int col = 0; col < width; col++) {
final int iR = rgbData.get(q++);
final int iG = rgbData.get(q++);
final int iB = rgbData.get(q++);
pixelInts[i++] = ((0xFF000000) | ((iR & 0xFF) << 16) | ((iG & 0xFF) << 8) | (iB & 0xFF));
}
}
// Set the data for the BufferedImage
if ((getImageOpenGL() == null) || (getImageOpenGL().getWidth() != width)
|| (getImageOpenGL().getHeight() != height)) {
imageOpenGL = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}
getImageOpenGL().setRGB(0, 0, width, height, pixelInts, 0, width);
}