當前位置: 首頁>>代碼示例>>Java>>正文


Java GLPixelStorageModes類代碼示例

本文整理匯總了Java中com.jogamp.opengl.util.GLPixelStorageModes的典型用法代碼示例。如果您正苦於以下問題:Java GLPixelStorageModes類的具體用法?Java GLPixelStorageModes怎麽用?Java GLPixelStorageModes使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GLPixelStorageModes類屬於com.jogamp.opengl.util包,在下文中一共展示了GLPixelStorageModes類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readToBufferedImage

import com.jogamp.opengl.util.GLPixelStorageModes; //導入依賴的package包/類
/**
 * Stolen from com.jogamp.opengl.util.awt.Screenshot.readToBufferedImage()
 * 
 * JOGL 2.1.2
 */
private static BufferedImage readToBufferedImage(
    int x,int y, int width, int height, boolean alpha) throws GLException {

  int bufImgType = (alpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
  int readbackType = (alpha ? GL2.GL_ABGR_EXT : GL2ES3.GL_BGR);

  // Allocate necessary storage
  BufferedImage image = new BufferedImage(width, height, bufImgType);

  GLContext glc = GLContext.getCurrent();
  GL gl = glc.getGL();

  // Set up pixel storage modes
  GLPixelStorageModes psm = new GLPixelStorageModes();
  psm.setPackAlignment(gl, 1);

  // read the BGR values into the image
  gl.glReadPixels(x, y, width, height, readbackType,
      GL.GL_UNSIGNED_BYTE,
      ByteBuffer.wrap(((DataBufferByte) image.getRaster().getDataBuffer()).getData()));

  // Restore pixel storage modes
  psm.restore(gl);

  if( glc.getGLDrawable().isGLOriented() ) {
    // Must flip BufferedImage vertically for correct results
    ImageUtil.flipImageVertically(image);
  }
  return image;
}
 
開發者ID:google,項目名稱:depan,代碼行數:36,代碼來源:Screenshots.java

示例2: writeToTargaFile

import com.jogamp.opengl.util.GLPixelStorageModes; //導入依賴的package包/類
/**
 * Takes a fast screenshot of the current OpenGL drawable to a Targa
 * file. Requires the OpenGL context for the desired drawable to be
 * current. Takes the screenshot from the last assigned read buffer,
 * or the OpenGL default read buffer if none has been specified by
 * the user (GL_FRONT for single-buffered configurations and GL_BACK
 * for double-buffered configurations). This is the fastest
 * mechanism for taking a screenshot of an application. Contributed
 * by Carsten Weisse of Bytonic Software (http://bytonic.de/).
 *
 * @param file the file to write containing the screenshot
 * @param x the starting x coordinate of the screenshot, measured from the lower-left
 * @param y the starting y coordinate of the screenshot, measured from the lower-left
 * @param width the width of the desired screenshot area
 * @param height the height of the desired screenshot area
 * @param alpha whether the alpha channel should be saved. If true,
 *   requires GL_EXT_abgr extension to be present.
 *
 * @throws GLException if an OpenGL context was not current or
 *   another OpenGL-related error occurred
 * @throws IOException if an I/O error occurred while writing the
 *   file
 */
public static void writeToTargaFile(File file,
                                    int x,
                                    int y,
                                    int width,
                                    int height,
                                    boolean alpha) throws GLException, IOException {
    if (alpha) {
        checkExtABGR();
    }

    TGAWriter writer = new TGAWriter();
    writer.open(file, width, height, alpha);
    ByteBuffer bgr = writer.getImageData();

    GL gl = GLContext.getCurrentGL();

    // Set up pixel storage modes
    GLPixelStorageModes psm = new GLPixelStorageModes();
    psm.setPackAlignment(gl, 1);

    int readbackType = (alpha ? GL2.GL_ABGR_EXT : GL2GL3.GL_BGR);

    // read the BGR values into the image buffer
    gl.glReadPixels(x, y, width, height, readbackType,
            GL.GL_UNSIGNED_BYTE, bgr);

    // Restore pixel storage modes
    psm.restore(gl);

    // close the file
    writer.close();
}
 
開發者ID:madebyjeffrey,項目名稱:TerraJ,代碼行數:56,代碼來源:Screenshot.java

示例3: readToBufferedImage

import com.jogamp.opengl.util.GLPixelStorageModes; //導入依賴的package包/類
/**
 * Takes a screenshot of the current OpenGL drawable to a
 * BufferedImage. Requires the OpenGL context for the desired
 * drawable to be current. Takes the screenshot from the last
 * assigned read buffer, or the OpenGL default read buffer if none
 * has been specified by the user (GL_FRONT for single-buffered
 * configurations and GL_BACK for double-buffered configurations).
 * Note that the scanlines of the resulting image are flipped
 * vertically in order to correctly match the OpenGL contents, which
 * takes time and is therefore not as fast as the Targa screenshot
 * function.
 *
 * @param x the starting x coordinate of the screenshot, measured from the lower-left
 * @param y the starting y coordinate of the screenshot, measured from the lower-left
 * @param width the width of the desired screenshot area
 * @param height the height of the desired screenshot area
 * @param alpha whether the alpha channel should be read back. If
 *   true, requires GL_EXT_abgr extension to be present.
 *
 * @throws GLException if an OpenGL context was not current or
 *   another OpenGL-related error occurred
 */
public static BufferedImage readToBufferedImage(int x,
                                                int y,
                                                int width,
                                                int height,
                                                boolean alpha) throws GLException {
    int bufImgType = (alpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
    int readbackType = (alpha ? GL2.GL_ABGR_EXT : GL2GL3.GL_BGR);

    if (alpha) {
        checkExtABGR();
    }

    // Allocate necessary storage
    BufferedImage image = new BufferedImage(width, height, bufImgType);

    GLContext glc = GLContext.getCurrent();
    GL gl = glc.getGL();

    // Set up pixel storage modes
    GLPixelStorageModes psm = new GLPixelStorageModes();
    psm.setPackAlignment(gl, 1);

    // read the BGR values into the image
    gl.glReadPixels(x, y, width, height, readbackType,
            GL.GL_UNSIGNED_BYTE,
            ByteBuffer.wrap(((DataBufferByte) image.getRaster().getDataBuffer()).getData()));

    // Restore pixel storage modes
    psm.restore(gl);

    if( glc.getGLDrawable().isGLOriented() ) {
        // Must flip BufferedImage vertically for correct results
        ImageUtil.flipImageVertically(image);
    }
    return image;
}
 
開發者ID:madebyjeffrey,項目名稱:TerraJ,代碼行數:59,代碼來源:Screenshot.java


注:本文中的com.jogamp.opengl.util.GLPixelStorageModes類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。