blob: 8e05b17eae30ea7e5898534e77809a43be76fd58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package demo;
import java.io.File;
import java.io.IOException;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.texture.TextureIO;
public class Screenshot {
ReadBufferUtil readBufferUtil = new ReadBufferUtil();
public void dispose() {
readBufferUtil.dispose();
}
public void surface2File(GLAutoDrawable drawable, String filename) {
GL gl = drawable.getGL();
// FIXME glFinish() is an expensive paranoia sync, should not be necessary due to spec
gl.glFinish();
readBufferUtil.fetchOffscreenTexture(drawable, gl);
gl.glFinish();
try {
surface2File(filename);
} catch (IOException ex) {
throw new RuntimeException("can not write survace to file", ex);
}
}
void surface2File(String filename) throws IOException {
File file = new File(filename);
TextureIO.write(readBufferUtil.getTextureData(), file);
System.err.println("Wrote: " + file.getAbsolutePath() + ", ...");
readBufferUtil.rewindPixelBuffer();
}
}
|