JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLReadBufferUtilTextureIOWrite01NEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.util.texture;
30
31import com.jogamp.newt.opengl.GLWindow;
32
33import com.jogamp.opengl.GLAutoDrawable;
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLEventListener;
36import com.jogamp.opengl.GLProfile;
37import com.jogamp.opengl.util.GLReadBufferUtil;
38import com.jogamp.opengl.util.texture.TextureIO;
39
40import com.jogamp.opengl.test.junit.util.UITestCase;
41import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
42import com.jogamp.opengl.test.junit.jogl.offscreen.WindowUtilNEWT;
43
44import org.junit.Assert;
45import org.junit.BeforeClass;
46import org.junit.Test;
47import org.junit.FixMethodOrder;
48import org.junit.runners.MethodSorters;
49
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
52 static GLProfile glp;
53 static GLCapabilities caps;
54 static int width, height;
55
56 @BeforeClass
57 public static void initClass() {
58 glp = GLProfile.getDefault();
59 Assert.assertNotNull(glp);
60 caps = new GLCapabilities(glp);
61 Assert.assertNotNull(caps);
62 caps.setAlphaBits(1); // req. alpha channel
63 width = 256;
64 height = 256;
65 }
66
67 @Test
68 public void testOnscreenWritePNG_TGA_PAM() throws InterruptedException {
69 final GLReadBufferUtil screenshotRGB = new GLReadBufferUtil(false, false);
70 final GLReadBufferUtil screenshotRGBA = new GLReadBufferUtil(true, false);
71 final GLWindow glWindow = GLWindow.create(caps);
72 Assert.assertNotNull(glWindow);
73 glWindow.setTitle("Shared Gears NEWT Test");
74 glWindow.setSize(width, height);
75 glWindow.addGLEventListener(new GearsES2(1));
76 glWindow.addGLEventListener(new GLEventListener() {
77 int f = 0;
78 public void init(final GLAutoDrawable drawable) {}
79 public void dispose(final GLAutoDrawable drawable) {}
80 public void display(final GLAutoDrawable drawable) {
81 snapshot(f++, null, drawable.getGL(), screenshotRGBA, TextureIO.PNG, null);
82 snapshot(f++, null, drawable.getGL(), screenshotRGB, TextureIO.PNG, null);
83 snapshot(f++, null, drawable.getGL(), screenshotRGBA, TextureIO.TGA, null);
84 snapshot(f++, null, drawable.getGL(), screenshotRGB, TextureIO.TGA, null);
85 snapshot(f++, null, drawable.getGL(), screenshotRGBA, TextureIO.PAM, null);
86 snapshot(f++, null, drawable.getGL(), screenshotRGB, TextureIO.PAM, null);
87 }
88 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
89 });
90 glWindow.setVisible(true);
91 Thread.sleep(60);
92 glWindow.destroy();
93 }
94
95 @Test
96 public void testOffscreenWritePNG() throws InterruptedException {
97 final GLReadBufferUtil screenshotRGB = new GLReadBufferUtil(false, false);
98 final GLReadBufferUtil screenshotRGBA = new GLReadBufferUtil(true, false);
99 final GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false);
100 final GLWindow glWindow = GLWindow.create(caps2);
101 Assert.assertNotNull(glWindow);
102 glWindow.setSize(width, height);
103 glWindow.addGLEventListener(new GearsES2(1));
104 glWindow.addGLEventListener(new GLEventListener() {
105 int f = 0;
106 public void init(final GLAutoDrawable drawable) {}
107 public void dispose(final GLAutoDrawable drawable) {}
108 public void display(final GLAutoDrawable drawable) {
109 snapshot(f, null, drawable.getGL(), screenshotRGBA, TextureIO.PNG, null);
110 snapshot(f, null, drawable.getGL(), screenshotRGB, TextureIO.PNG, null);
111 f++;
112 }
113 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
114 });
115 glWindow.setVisible(true);
116 Thread.sleep(60);
117 glWindow.destroy();
118 }
119
120 public static void main(final String args[]) {
121 org.junit.runner.JUnitCore.main(TestGLReadBufferUtilTextureIOWrite01NEWT.class.getName());
122 }
123}
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
static GLCapabilities fixCaps(final GLCapabilities caps, final boolean onscreen, final boolean pbuffer, final boolean undecorated)
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
static final String TGA
Constant which can be used as a file suffix to indicate a Targa file, value {@value}.
Definition: TextureIO.java:176
static final String PAM
Constant which can be used as a file suffix to indicate a PAM file, NetPbm magic 7 - binary RGB and R...
Definition: TextureIO.java:187
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Definition: TextureIO.java:171
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.