当前位置: 首页>>代码示例>>Java>>正文


Java GL2.glPixelStorei方法代码示例

本文整理汇总了Java中com.jogamp.opengl.GL2.glPixelStorei方法的典型用法代码示例。如果您正苦于以下问题:Java GL2.glPixelStorei方法的具体用法?Java GL2.glPixelStorei怎么用?Java GL2.glPixelStorei使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jogamp.opengl.GL2的用法示例。


在下文中一共展示了GL2.glPixelStorei方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:46,代码来源:ChipCanvas.java


注:本文中的com.jogamp.opengl.GL2.glPixelStorei方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。