Screenshot without the frame on the screen

Is it in any way possible to render a frame via jogl directly into a file and not show it on the screen?
I have some code to draw just one frame and create a screenshot, but I haven’t figured out a way to make this screenshot without drawing the frame on the screen first.
thx marv

Do a search for pbuffers - they are used for off screen rendering in OpenGL. I haven’t used them in JOGL, but I am sure it supports them.

here’s the snapshot code I use, don’t i don’t know if it is 100% solving your problem


       ByteBuffer pixelsRGB = BufferUtils.newByteBuffer(width * height * 3);

        GL gl = drawable.getGL();

        gl.glReadBuffer(GL.GL_BACK);
        gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);

        gl.glReadPixels(0,                   // GLint x
                0,                   // GLint y
                width,                   // GLsizei width
                height,             // GLsizei height
                GL.GL_RGB,             // GLenum format
                GL.GL_UNSIGNED_BYTE,       // GLenum type
                pixelsRGB);             // GLvoid *pixels

        int[] pixelInts = new int[width * height];

        // Convert RGB bytes to ARGB ints with no transparency. Flip image 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[]
        int w3 = width * 3;        // Number of bytes in each row

        for (int row = 0; row < height; row++) {
            p -= w3;
            q = p;
            for (int col = 0; col < width; col++) {
                int iR = pixelsRGB.get(q++);
                int iG = pixelsRGB.get(q++);
                int iB = pixelsRGB.get(q++);

                pixelInts[i++] = 0xFF000000
                        | ((iR & 0x000000FF) << 16)
                        | ((iG & 0x000000FF) << 8)
                        | (iB & 0x000000FF);
            }
        }

        BufferedImage bufferedImage =
                new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        bufferedImage.setRGB(0, 0, width, height, pixelInts, 0, width);

        try {
            ImageIO.write(bufferedImage, "PNG", new File(fileName));
        } catch (IOException e) {
            e.printStackTrace();
        }


I’m still stuck with this problem. Just one example on how to do offscreen rendering with pbuffers and jogl would be great…

Instead of creating a GLCanvas, Frame, etc. to show your stuff on screen, create your GLAutoDrawable using GLDrawableFactory.createGLPbuffer() instead. Then attach your GLEventListener to it instead of the GLCanvas and your program should work exactly the same as if it were being rendered on screen; note you will have to call GLPbuffer.display() to force it to draw. At the end of your display() routine you can use glReadPixels to capture the output into a ByteBuffer. The jogl-demos workspace contains several examples of rendering to pbuffers, though none are completely trivial. Pepijn’s NeHe ports may contain a pbuffer example but I’m not sure.