JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTextureSequence01AWT.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.util.texture;
2
3import java.awt.Frame;
4import java.io.IOException;
5
6import com.jogamp.opengl.GLAutoDrawable;
7import com.jogamp.opengl.GLCapabilities;
8import com.jogamp.opengl.GLEventListener;
9import com.jogamp.opengl.GLProfile;
10import com.jogamp.opengl.awt.GLCanvas;
11
12import org.junit.Assert;
13import org.junit.Assume;
14import org.junit.BeforeClass;
15import org.junit.Test;
16import org.junit.FixMethodOrder;
17import org.junit.runners.MethodSorters;
18
19import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureSequenceCubeES2;
20import com.jogamp.opengl.test.junit.util.MiscUtils;
21import com.jogamp.opengl.test.junit.util.QuitAdapter;
22import com.jogamp.opengl.test.junit.util.UITestCase;
23import com.jogamp.opengl.util.Animator;
24import com.jogamp.opengl.util.texture.ImageSequence;
25import com.jogamp.opengl.util.texture.TextureIO;
26
27@FixMethodOrder(MethodSorters.NAME_ASCENDING)
29 static boolean showFPS = false;
30 static int width = 510;
31 static int height = 300;
32 static boolean useBuildInTexLookup = false;
33 static long duration = 500; // ms
34 static GLProfile glp;
35 static GLCapabilities caps;
36
37 @BeforeClass
38 public static void initClass() {
39 glp = GLProfile.getGL2ES2();
40 Assert.assertNotNull(glp);
41 caps = new GLCapabilities(glp);
42 Assert.assertNotNull(caps);
43 }
44
45 void testImpl() throws InterruptedException {
46 final GLCanvas glc = new GLCanvas(caps);
47 final Frame frame = new Frame("TestTextureSequence01AWT");
48 Assert.assertNotNull(frame);
49 frame.add(glc);
50
51 final ImageSequence texSource = new ImageSequence(0, useBuildInTexLookup);
53 @Override
54 public void init(final GLAutoDrawable drawable) {
55 try {
56 texSource.addFrame(drawable.getGL(), TestTextureSequence01AWT.class, "test-ntscP_3-01-160x90.png", TextureIO.PNG);
57 } catch (final IOException e) {
58 e.printStackTrace();
59 }
60 }
61 @Override
62 public void dispose(final GLAutoDrawable drawable) { }
63 @Override
64 public void display(final GLAutoDrawable drawable) { }
65 @Override
66 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
67 });
68 glc.addGLEventListener(new TextureSequenceCubeES2(texSource, false, -2.3f, 0f, 0f));
69
70 final QuitAdapter quitAdapter = new QuitAdapter();
71 new com.jogamp.newt.event.awt.AWTKeyAdapter(quitAdapter, glc).addTo(glc);
72 new com.jogamp.newt.event.awt.AWTWindowAdapter(quitAdapter, glc).addTo(glc);
73
74 try {
75 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
76 public void run() {
77 frame.setSize(width, height);
78 frame.setVisible(true);
79 }});
80 } catch( final Throwable throwable ) {
81 throwable.printStackTrace();
82 Assume.assumeNoException( throwable );
83 }
84
85 final Animator animator = new Animator(glc);
86 animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
87 animator.start();
88
89 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
90 Thread.sleep(100);
91 }
92
93 animator.stop();
94 Assert.assertFalse(animator.isAnimating());
95 Assert.assertFalse(animator.isStarted());
96 try {
97 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
98 public void run() {
99 frame.setVisible(false);
100 frame.remove(glc);
101 frame.dispose();
102 }});
103 } catch( final Throwable throwable ) {
104 throwable.printStackTrace();
105 Assume.assumeNoException( throwable );
106 }
107 }
108
109 @Test
110 public void test1() throws InterruptedException {
111 testImpl();
112 }
113
114 public static void main(final String[] args) {
115 for(int i=0; i<args.length; i++) {
116 if(args[i].equals("-time")) {
117 i++;
118 duration = MiscUtils.atol(args[i], duration);
119 } else if(args[i].equals("-width")) {
120 i++;
121 width = MiscUtils.atoi(args[i], width);
122 } else if(args[i].equals("-height")) {
123 i++;
124 height = MiscUtils.atoi(args[i], height);
125 } else if(args[i].equals("-shaderBuildIn")) {
126 useBuildInTexLookup = true;
127 }
128 }
129 org.junit.runner.JUnitCore.main(TestTextureSequence01AWT.class.getName());
130 }
131
132}
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
Simple TextureSequence implementation allowing existing textures or image streams to be used and repl...
final TextureSequence.TextureFrame addFrame(final GL gl, final Texture tex)
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.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.