aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/scripts/tests.sh6
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java176
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java194
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java16
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/button-pressed-145x53.pngbin0 -> 8603 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/button-released-145x53.pngbin0 -> 9429 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java131
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/ImageSeqButton.java63
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/MediaPlayerButton.java131
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureSeqButton.java (renamed from src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureButton.java)17
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/SingleTextureSeqFrame.java126
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01NEWT.java11
13 files changed, 638 insertions, 243 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 0c77dcec1..7ceb836b0 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -123,7 +123,7 @@ function jrun() {
#D_ARGS="-Djogl.debug.GLContext -Dnativewindow.debug.JAWT -Dnewt.debug.Window"
#D_ARGS="-Dnativewindow.debug.JAWT -Djogl.debug.GLCanvas"
#D_ARGS="-Dnativewindow.debug.JAWT -Djogamp.debug.TaskBase.TraceSource"
- D_ARGS="-Dnativewindow.debug.JAWT"
+ #D_ARGS="-Dnativewindow.debug.JAWT"
#D_ARGS="-Djogl.debug.GLContext.TraceSwitch"
#D_ARGS="-Djogl.debug.GLContext -Djogl.debug.GLContext.TraceSwitch"
#D_ARGS="-Djogl.debug.FixedFuncPipeline -Djogl.debug.GLSLCode"
@@ -347,7 +347,7 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLCanvasAWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLProfile00NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLProfile01NEWT $*
-testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestVersionSemanticsNOUI $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestVersionSemanticsNOUI $*
#
# demos (any TK, more user driven tests)
@@ -751,7 +751,7 @@ testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestVersionSemanticsNOUI $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.ui.UINewtDemo01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUTextNewtDemo $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPURegionNewtDemo $*
-#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUUISceneNewtDemo $*
+testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUUISceneNewtDemo $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple $*
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java
new file mode 100644
index 000000000..4622d6975
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java
@@ -0,0 +1,176 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.util.texture;
+
+import java.io.IOException;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.common.util.IOUtil;
+
+/**
+ * Simple {@link TextureSequence} implementation
+ * allowing {@link #addFrame(GL, Texture) existing textures}
+ * or {@link #addFrame(GL, Class, String, String) image streams}
+ * to be used and <i>replayed</i> as {@link TextureSequence.TextureFrame frames}.
+ */
+public class ImageSequence implements TextureSequence {
+ private final int textureUnit;
+ private final boolean useBuildInTexLookup;
+ private final List<TextureSequence.TextureFrame> frames = new ArrayList<TextureSequence.TextureFrame>();
+ private final int[] texMinMagFilter = { GL.GL_NEAREST, GL.GL_NEAREST };
+ private final int[] texWrapST = { GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE };
+ private volatile int frameIdx = 0;
+ private volatile boolean manualStepping = false;
+
+ public ImageSequence(final int textureUnit, final boolean useBuildInTexLookup) {
+ this.textureUnit = textureUnit;
+ this.useBuildInTexLookup = useBuildInTexLookup;
+ }
+
+ public void setParams(final int magFilter, final int minFilter, final int wrapS, final int wrapT) {
+ texMinMagFilter[0] = minFilter;
+ texMinMagFilter[1] = magFilter;
+ texWrapST[0] = wrapS;
+ texWrapST[1] = wrapT;
+ }
+
+ public final void addFrame(final GL gl, final Texture tex) {
+ final TextureSequence.TextureFrame frame = new TextureSequence.TextureFrame(tex);
+ frames.add(frame);
+ tex.bind(gl);
+ gl.glTexParameteri(getTextureTarget(), GL.GL_TEXTURE_MIN_FILTER, texMinMagFilter[0]);
+ gl.glTexParameteri(getTextureTarget(), GL.GL_TEXTURE_MAG_FILTER, texMinMagFilter[1]);
+ gl.glTexParameteri(getTextureTarget(), GL.GL_TEXTURE_WRAP_S, texWrapST[0]);
+ gl.glTexParameteri(getTextureTarget(), GL.GL_TEXTURE_WRAP_T, texWrapST[1]);
+ }
+
+ public final void addFrame(final GL gl, final Class<?> context, final String imageResourcePath, final String imageSuffix) throws IOException {
+ URLConnection urlConn = IOUtil.getResource(context, imageResourcePath);
+ if(null != urlConn) {
+ final TextureData texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, imageSuffix);
+ final Texture tex = new Texture(getTextureTarget());
+ tex.updateImage(gl, texData);
+ addFrame(gl, tex);
+ }
+ }
+ public final int getFrameCount() { return frames.size(); }
+ public final int getCurrentIdx() { return frameIdx; }
+ public final void setCurrentIdx(final int idx) throws IndexOutOfBoundsException {
+ if( 0 > idx || idx >= frames.size() ) {
+ throw new IndexOutOfBoundsException("idx shall be within 0 <= "+idx+" < "+frames.size());
+ }
+ frameIdx=idx;
+ }
+ public final void setManualStepping(final boolean v) { manualStepping = v; }
+ public final boolean getManualStepping() { return manualStepping; }
+ public final TextureSequence.TextureFrame getFrame(final int idx) { return frames.get(idx); }
+
+ public void destroy(GL gl) throws GLException {
+ for(int i=frames.size()-1; i>=0; i--) {
+ frames.get(i).getTexture().destroy(gl);
+ }
+ frames.clear();
+ }
+
+ @Override
+ public int getTextureTarget() {
+ return GL.GL_TEXTURE_2D;
+ }
+
+ @Override
+ public int getTextureUnit() {
+ return textureUnit;
+ }
+
+ @Override
+ public int[] getTextureMinMagFilter() {
+ return texMinMagFilter;
+ }
+
+ @Override
+ public int[] getTextureWrapST() {
+ return texWrapST;
+ }
+
+ @Override
+ public boolean isTextureAvailable() { return frames.size() > 0; }
+
+ @Override
+ public TextureSequence.TextureFrame getLastTexture() throws IllegalStateException {
+ return frames.get(frameIdx); // may return null
+ }
+
+ @Override
+ public TextureSequence.TextureFrame getNextTexture(GL gl) throws IllegalStateException {
+ if( !manualStepping ) {
+ frameIdx = ( frameIdx + 1 ) % frames.size();
+ }
+ return frames.get(frameIdx);
+ }
+
+ @Override
+ public String getRequiredExtensionsShaderStub() throws IllegalStateException {
+ return "// TextTextureSequence: No extensions required\n";
+ }
+
+ @Override
+ public String getTextureSampler2DType() throws IllegalStateException {
+ return "sampler2D" ;
+ }
+
+ private String textureLookupFunctionName = "myTexture2D";
+
+ @Override
+ public String getTextureLookupFunctionName(String desiredFuncName) throws IllegalStateException {
+ if(useBuildInTexLookup) {
+ return "texture2D";
+ }
+ if(null != desiredFuncName && desiredFuncName.length()>0) {
+ textureLookupFunctionName = desiredFuncName;
+ }
+ return textureLookupFunctionName;
+ }
+
+ @Override
+ public String getTextureLookupFragmentShaderImpl() throws IllegalStateException {
+ if(useBuildInTexLookup) {
+ return "";
+ }
+ return
+ "\n"+
+ "vec4 "+textureLookupFunctionName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
+ " return texture2D(image, texCoord);\n"+
+ "}\n\n";
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
index df9c6381f..a2c3faecf 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
@@ -32,18 +32,20 @@ import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.VectorUtil;
import com.jogamp.opengl.test.junit.graph.demos.ui.CrossHair;
+import com.jogamp.opengl.test.junit.graph.demos.ui.GLEventListenerButton;
import com.jogamp.opengl.test.junit.graph.demos.ui.Label;
import com.jogamp.opengl.test.junit.graph.demos.ui.LabelButton;
+import com.jogamp.opengl.test.junit.graph.demos.ui.MediaPlayerButton;
import com.jogamp.opengl.test.junit.graph.demos.ui.RoundButton;
import com.jogamp.opengl.test.junit.graph.demos.ui.SceneUIController;
-import com.jogamp.opengl.test.junit.graph.demos.ui.TextureButton;
+import com.jogamp.opengl.test.junit.graph.demos.ui.ImageSeqButton;
import com.jogamp.opengl.test.junit.graph.demos.ui.UIShape;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
import com.jogamp.opengl.util.GLReadBufferUtil;
import com.jogamp.opengl.util.av.GLMediaPlayer;
import com.jogamp.opengl.util.av.GLMediaPlayerFactory;
-import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener;
-import com.jogamp.opengl.util.av.GLMediaPlayer.StreamException;
-import com.jogamp.opengl.util.texture.TextureSequence.TextureFrame;
+import com.jogamp.opengl.util.texture.ImageSequence;
+import com.jogamp.opengl.util.texture.TextureIO;
public class GPUUISceneGLListener0A implements GLEventListener {
@@ -82,6 +84,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
private Label[] labels = null;
private String[] strings = null;
private final List<RoundButton> buttons = new ArrayList<RoundButton>();
+ private int buttonsLeftCount = 0;
private Label truePtSizeLabel = null;
private Label jogampLabel = null;
private Label fpsLabel = null;
@@ -167,15 +170,16 @@ public class GPUUISceneGLListener0A implements GLEventListener {
buttons.clear();
final float buttonXSize = buttonXSizePVP * width;
- final float buttonYSize = buttonYSizePVP * height;
+ // final float buttonYSize = buttonYSizePVP * height;
+ final float buttonYSize = buttonXSize / 2.5f;
System.err.println("Button Size: "+buttonXSizePVP+" x "+buttonYSizePVP+" * "+width+" x "+height+" -> "+buttonXSize+" x "+buttonYSize);
- final float xstart = 0f;
- final float ystart = 0f;
+ final float xStartLeft = 0f; // aligned to left edge w/ space via reshape
+ final float yStartTop = 0f; // aligned to top edge w/ space via reshape
final float diffX = 1.2f * buttonXSize;
final float diffY = 1.5f * buttonYSize;
LabelButton button = new LabelButton(SVertex.factory(), renderModes, font, "Next Text", buttonXSize, buttonYSize);
- button.translate(xstart,ystart-diffY*buttons.size(), 0f);
+ button.translate(xStartLeft,yStartTop-diffY*buttons.size(), 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -192,7 +196,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
button = new LabelButton(SVertex.factory(), renderModes, font, "Show FPS", buttonXSize, buttonYSize);
button.setName(100); // FIXME: DEBUG tag
- button.translate(xstart,ystart - diffY*buttons.size(), 0f);
+ button.translate(xStartLeft,yStartTop - diffY*buttons.size(), 0f);
button.setToggleable(true);
button.setToggle(fpsLabel.isEnabled());
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@@ -208,7 +212,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
buttons.add(button);
button = new LabelButton(SVertex.factory(), renderModes, font, "v-sync", buttonXSize, buttonYSize);
- button.translate(xstart,ystart - diffY*buttons.size(), 0f);
+ button.translate(xStartLeft,yStartTop - diffY*buttons.size(), 0f);
button.setToggleable(true);
button.setToggle(gl.getSwapInterval()>0);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@@ -231,7 +235,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
buttons.add(button);
button = new LabelButton(SVertex.factory(), renderModes, font, "< tilt >", buttonXSize, buttonYSize);
- button.translate(xstart,ystart - diffY*buttons.size(), 0f);
+ button.translate(xStartLeft,yStartTop - diffY*buttons.size(), 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -253,7 +257,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
if( pass2Mode ) { // second column to the left
button = new LabelButton(SVertex.factory(), renderModes, font, "< samples >", buttonXSize, buttonYSize);
- button.translate(xstart,ystart - diffY*buttons.size(), 0f);
+ button.translate(xStartLeft,yStartTop - diffY*buttons.size(), 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -279,7 +283,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
buttons.add(button);
button = new LabelButton(SVertex.factory(), renderModes, font, "< quality >", buttonXSize, buttonYSize);
- button.translate(xstart,ystart - diffY*buttons.size(), 0f);
+ button.translate(xStartLeft,yStartTop - diffY*buttons.size(), 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -307,7 +311,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
button = new LabelButton(SVertex.factory(), renderModes, font, "Quit", buttonXSize, buttonYSize);
- button.translate(xstart,ystart - diffY*buttons.size(), 0f);
+ button.translate(xStartLeft,yStartTop - diffY*buttons.size(), 0f);
button.setColor(0.7f, 0.0f, 0.0f, 1.0f);
button.setLabelColor(1.2f, 1.2f, 1.2f);
button.setPressedColorMod(1.1f, 0.0f, 0.0f, 1.0f);
@@ -333,7 +337,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
int j = 1; // column
int k = 0; // row
button = new LabelButton(SVertex.factory(), renderModes, font, "y flip", buttonXSize, buttonYSize);
- button.translate(xstart - diffX*j,ystart - diffY*k, 0f);
+ button.translate(xStartLeft - diffX*j,yStartTop - diffY*k, 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -344,7 +348,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
k++;
button = new LabelButton(SVertex.factory(), renderModes, font, "x flip", buttonXSize, buttonYSize);
- button.translate(xstart - diffX*j,ystart - diffY*k, 0f);
+ button.translate(xStartLeft - diffX*j,yStartTop - diffY*k, 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -355,7 +359,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
k++;
button = new LabelButton(SVertex.factory(), renderModes, font, "+", buttonXSize, buttonYSize);
- button.translate(xstart - diffX*j,ystart - diffY*k, 0f);
+ button.translate(xStartLeft - diffX*j,yStartTop - diffY*k, 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -382,7 +386,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
k++;
button = new LabelButton(SVertex.factory(), renderModes, font, "< space >", buttonXSize, buttonYSize);
- button.translate(xstart - diffX*j,ystart - diffY*k, 0f);
+ button.translate(xStartLeft - diffX*j,yStartTop - diffY*k, 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -406,7 +410,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
k++;
button = new LabelButton(SVertex.factory(), renderModes, font, "< corner >", buttonXSize, buttonYSize);
- button.translate(xstart - diffX*j,ystart - diffY*k, 0f);
+ button.translate(xStartLeft - diffX*j,yStartTop - diffY*k, 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -431,7 +435,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
k++;
button = new LabelButton(SVertex.factory(), renderModes, font, "reset", buttonXSize, buttonYSize);
- button.translate(xstart - diffX*j,ystart - diffY*k, 0f);
+ button.translate(xStartLeft - diffX*j,yStartTop - diffY*k, 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -442,7 +446,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
k++;
button = new LabelButton(SVertex.factory(), renderModes, font, "screenshot", buttonXSize, buttonYSize);
- button.translate(xstart - diffX*j,ystart - diffY*k, 0f);
+ button.translate(xStartLeft - diffX*j,yStartTop - diffY*k, 0f);
button.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -459,75 +463,28 @@ public class GPUUISceneGLListener0A implements GLEventListener {
k++;
}
+ buttonsLeftCount = buttons.size();
+
+ final float button2XSize = 2f*buttonXSize;
+ final float button2YSize = 2f*buttonYSize;
+ final float xStartRight = -button2XSize - 8f; // aligned to right edge via reshape
+
if(true) {
final GLMediaPlayer mPlayer = GLMediaPlayerFactory.createDefault();
- final TextureButton texButton = new TextureButton(renderer.getRenderState().getVertexFactory(), renderModes,
- 2f*buttonXSize, 2f*buttonYSize, mPlayer) {
- @Override
- protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) {
- mPlayer.destroy(gl);
- }
- @Override
- public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount) {
- if( GLMediaPlayer.State.Initialized == mPlayer.getState() ) {
- try {
- System.err.println("XXX InitGL.pre: "+mPlayer);
- mPlayer.initGL(gl);
- mPlayer.setAudioVolume( 0f );
- System.err.println("XXX Play.pre: "+mPlayer);
- GLMediaPlayer.State r = mPlayer.play();
- System.err.println("XXX Play.post: "+r+", "+mPlayer);
- markStateDirty();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- super.drawShape(gl, renderer, sampleCount);
- markStateDirty(); // keep on going
- } };
- texButton.setEnabled(false); // wait until data is avail. (shader)
- texButton.translate(xstart + diffX*5, ystart - diffY*1, 0f);
- texButton.setToggleable(true);
- texButton.setToggle(false); // toggle == false -> mute audio
- texButton.setToggleOffColorMod(0f, 1f, 0f, 1.0f);
- texButton.addMouseListener(dragZoomRotateListener);
- texButton.addMouseListener(new UIShape.MouseGestureAdapter() {
+ final MediaPlayerButton mPlayerButton = new MediaPlayerButton(renderer.getRenderState().getVertexFactory(), renderModes,
+ button2XSize, button2YSize, mPlayer);
+ mPlayerButton.addDefaultEventListener();
+ mPlayerButton.translate(xStartRight, yStartTop - diffY*1, 0f);
+ mPlayerButton.setToggleable(true);
+ mPlayerButton.setToggle(false); // toggle == false -> mute audio
+ mPlayerButton.setToggleOffColorMod(0f, 1f, 0f, 1.0f);
+ mPlayerButton.addMouseListener(dragZoomRotateListener);
+ mPlayerButton.addMouseListener(new UIShape.MouseGestureAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
- mPlayer.setAudioVolume( texButton.isToggleOn() ? 1f : 0f );
+ mPlayer.setAudioVolume( mPlayerButton.isToggleOn() ? 1f : 0f );
} } );
- buttons.add(texButton);
- mPlayer.addEventListener(new GLMediaEventListener() {
- @Override
- public void newFrameAvailable(GLMediaPlayer ts, TextureFrame newFrame, long when) {
- // texButton.markStateDirty();
- }
-
- @Override
- public void attributesChanged(final GLMediaPlayer mp, int event_mask, long when) {
- System.err.println("MovieCube AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when);
- System.err.println("MovieCube State: "+mp);
- if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) {
- texButton.setEnabled(true); // data and shader is available ..
- }
- if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) {
- // FIXME: mPlayer.resetGLState();
- }
- if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) {
- new Thread() {
- public void run() {
- // loop for-ever ..
- mPlayer.seek(0);
- mPlayer.play();
- } }.start();
- } else if( 0 != ( GLMediaEventListener.EVENT_CHANGE_ERR & event_mask ) ) {
- final StreamException se = mPlayer.getStreamException();
- if( null != se ) {
- se.printStackTrace();
- }
- }
- }
- });
+ buttons.add(mPlayerButton);
try {
final URI streamLoc = new URI("http://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4");
mPlayer.initStream(streamLoc, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.TEXTURE_COUNT_DEFAULT);
@@ -535,6 +492,51 @@ public class GPUUISceneGLListener0A implements GLEventListener {
e1.printStackTrace();
}
}
+ if( true ) {
+ final ImageSequence imgSeq = new ImageSequence(0, true);
+ final ImageSeqButton imgButton = new ImageSeqButton(renderer.getRenderState().getVertexFactory(), renderModes,
+ button2XSize, button2YSize, imgSeq);
+ try {
+ imgSeq.addFrame(gl, GPUUISceneGLListener0A.class, "button-released-145x53.png", TextureIO.PNG);
+ imgSeq.addFrame(gl, GPUUISceneGLListener0A.class, "button-pressed-145x53.png", TextureIO.PNG);
+ } catch (IOException e2) {
+ e2.printStackTrace();
+ }
+ imgSeq.setManualStepping(true);
+ imgButton.translate(xStartRight, yStartTop - diffY*2.5f, 0f);
+ imgButton.addMouseListener(dragZoomRotateListener);
+ imgButton.addMouseListener(new UIShape.MouseGestureAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {
+ imgButton.setCurrentIdx(1);
+ System.err.println("XXX: "+imgButton);
+ }
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ imgButton.setCurrentIdx(0);
+ } } );
+ buttons.add(imgButton);
+ }
+ if( true ) {
+ final GearsES2 glel = new GearsES2(0);
+ glel.setVerbose(false);
+ glel.setClearColor(new float[] { 0.9f, 0.9f, 0.9f, 1f } );
+ final GLEventListenerButton glelButton = new GLEventListenerButton(renderer.getRenderState().getVertexFactory(), renderModes,
+ button2XSize, button2YSize,
+ 0, glel, false /* useAlpha */,
+ (int)(button2XSize), (int)(button2YSize));
+ glelButton.setToggleable(true);
+ glelButton.setToggle(true); // toggle == true -> animation
+ glelButton.setAnimate(true);
+ glelButton.translate(xStartRight, yStartTop - diffY*4f, 0f);
+ glelButton.addMouseListener(dragZoomRotateListener);
+ glelButton.addMouseListener(new UIShape.MouseGestureAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ glelButton.setAnimate( glelButton.isToggleOn() );
+ } } );
+ buttons.add(glelButton);
+ }
}
private void initTexts() {
@@ -547,13 +549,14 @@ public class GPUUISceneGLListener0A implements GLEventListener {
" - Z Translation\n"+
" - Ctrl: Y-Rotation (Shift: X-Rotation)\n"+
" - Tilt, Space and Corner\n"+
- " - Their respective action via wheel (shift = other value)\n"+
+ " - Their respective action via wheel\n"+
+ " (shift = other value)\n"+
"\n"+
"- Mouse Drag On Object\n"+
" - Click on Object and drag mouse\n"+
- " - Notice current postion in status line at bottom\n"+
+ " - Current postion in status line at bottom\n"+
"\n"+
- "- Tilt Button Rotate Whole Button Group\n";
+ "- Tilt Button Rotate Whole Button Group";
strings[i++] = "abcdefghijklmn\nopqrstuvwxyz\n"+
"ABCDEFGHIJKL\n"+
@@ -711,7 +714,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
if(null == labels[currentText]) {
final float pixelSizeFixed = fontSizeFixedPVP * drawable.getHeight();
- final float dyTop = drawable.getHeight() * relTop;
+ final float dyTop = drawable.getHeight() - 2f*jogampLabel.getLineHeight();
final float dxRight = drawable.getWidth() * relMiddle;
labels[currentText] = new Label(renderer.getRenderState().getVertexFactory(), renderModes, font, pixelSizeFixed, strings[currentText]);
labels[currentText].setColor(0.1f, 0.1f, 0.1f, 1.0f);
@@ -769,15 +772,20 @@ public class GPUUISceneGLListener0A implements GLEventListener {
final float dyTop = dh * relTop;
final float dxMiddle = dw * relMiddle;
final float dxLeft = dw * relLeft;
+ final float dxRight = dw;
- for(int i=0; i<buttons.size(); i++) {
+ for(int i=0; i<buttons.size() && i<buttonsLeftCount; i++) {
buttons.get(i).translate(dxLeft, dyTop, dz);
}
- jogampLabel.translate(dxMiddle, dyTop, dz);
- truePtSizeLabel.translate(dxMiddle, dyTop, dz);
+ for(int i=buttonsLeftCount; i<buttons.size(); i++) {
+ buttons.get(i).translate(dxRight, dyTop, dz);
+ }
+ final float dyTopLabel = drawable.getHeight() - 2f*jogampLabel.getLineHeight();
+ jogampLabel.translate(dxMiddle, dyTopLabel, dz);
+ truePtSizeLabel.translate(dxMiddle, dyTopLabel, dz);
fpsLabel.translate(0f, 0f, 0f);
if( null != labels[currentText] ) {
- labels[currentText].translate(dxMiddle, dyTop, 0f);
+ labels[currentText].translate(dxMiddle, dyTopLabel, 0f);
}
crossHairCtr.translate(dw/2f, dh/2f, 0f);
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java
index a4da58eac..79f6d7bb8 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java
@@ -21,22 +21,26 @@ public class GPUUISceneNewtDemo {
static boolean GraphMSAAMode = false;
public static void main(String[] args) {
+ int wwidth = 800, wheight = 400;
if( 0 != args.length ) {
- SceneMSAASamples = 0;
- GraphMSAAMode = false;
- GraphVBAAMode = false;
-
for(int i=0; i<args.length; i++) {
if(args[i].equals("-smsaa")) {
i++;
SceneMSAASamples = MiscUtils.atoi(args[i], SceneMSAASamples);
+ GraphMSAAMode = false;
+ GraphVBAAMode = false;
} else if(args[i].equals("-gmsaa")) {
GraphMSAAMode = true;
GraphVBAAMode = false;
} else if(args[i].equals("-gvbaa")) {
- i++;
GraphMSAAMode = false;
GraphVBAAMode = true;
+ } else if(args[i].equals("-width")) {
+ i++;
+ wwidth = MiscUtils.atoi(args[i], wwidth);
+ } else if(args[i].equals("-height")) {
+ i++;
+ wheight = MiscUtils.atoi(args[i], wheight);
}
}
}
@@ -64,7 +68,7 @@ public class GPUUISceneNewtDemo {
final GLWindow window = GLWindow.create(caps);
window.setPosition(10, 10);
- window.setSize(800, 400);
+ window.setSize(wwidth, wheight);
window.setTitle("GraphUI Newt Demo: graph["+Region.getRenderModeString(rmode)+"], msaa "+SceneMSAASamples);
final RenderState rs = RenderState.createRenderState(SVertex.factory());
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/button-pressed-145x53.png b/src/test/com/jogamp/opengl/test/junit/graph/demos/button-pressed-145x53.png
new file mode 100644
index 000000000..1eba3a09e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/button-pressed-145x53.png
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/button-released-145x53.png b/src/test/com/jogamp/opengl/test/junit/graph/demos/button-released-145x53.png
new file mode 100644
index 000000000..fe223c6d3
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/button-released-145x53.png
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java
new file mode 100644
index 000000000..9eb32c6f8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java
@@ -0,0 +1,131 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.graph.demos.ui;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLOffscreenAutoDrawable;
+
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.geom.Vertex.Factory;
+import com.jogamp.opengl.FBObject;
+import com.jogamp.opengl.util.texture.ImageSequence;
+import com.jogamp.opengl.util.texture.Texture;
+
+/**
+ * GPU based resolution independent Button impl,
+ * rendering {@link GLEventListener} content via FBO as an {@link ImageSequence}.
+ */
+public class GLEventListenerButton extends TextureSeqButton {
+ private final GLEventListener glel;
+ private final boolean useAlpha;
+ private volatile int fboWidth = 200;
+ private volatile int fboHeight = 200;
+ private volatile GLOffscreenAutoDrawable.FBO fboGLAD = null;
+ private boolean animateGLEL = false;
+
+ public GLEventListenerButton(final Factory<? extends Vertex> factory, final int renderModes,
+ final float width, final float height, final int textureUnit,
+ final GLEventListener glel, final boolean useAlpha, final int fboWidth, final int fboHeight) {
+ super(factory, renderModes, width, height, new ImageSequence(textureUnit, true));
+ this.glel = glel;
+ this.useAlpha = useAlpha;
+
+ setColor(0.95f, 0.95f, 0.95f, 1.0f);
+ setPressedColorMod(1f, 1f, 1f, 0.9f);
+ setToggleOffColorMod(0.8f, 0.8f, 0.8f, 1.0f);
+ setToggleOnColorMod(1.0f, 1.0f, 1.0f, 1.0f);
+
+ this.fboWidth = fboWidth;
+ this.fboHeight = fboHeight;
+ }
+
+ public final void setAnimate(boolean v) { animateGLEL = v; }
+ public final boolean getAnimate() { return animateGLEL; }
+
+ public final void setFBOSize(final int fboWidth, final int fboHeight) {
+ this.fboWidth = fboWidth;
+ this.fboHeight = fboHeight;
+ }
+
+ public final GLOffscreenAutoDrawable.FBO getFBOAutoDrawable() { return fboGLAD; }
+
+ @Override
+ public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount) {
+ if( null == fboGLAD ) {
+ final ImageSequence imgSeq = (ImageSequence)texSeq;
+
+ final GLContext ctx = gl.getContext();
+ final GLDrawable drawable = ctx.getGLDrawable();
+ final GLCapabilitiesImmutable capsHas = drawable.getChosenGLCapabilities();
+ final GLCapabilities caps = (GLCapabilities) capsHas.cloneMutable();
+ caps.setFBO(true);
+ caps.setDoubleBuffered(false);
+ if( !useAlpha ) {
+ caps.setAlphaBits(0);
+ }
+ final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
+
+ fboGLAD = (GLOffscreenAutoDrawable.FBO) factory.createOffscreenAutoDrawable(
+ drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(),
+ caps, null, fboWidth, fboHeight);
+ fboWidth = 0;
+ fboHeight = 0;
+ fboGLAD.setSharedContext(ctx);
+ fboGLAD.setTextureUnit(imgSeq.getTextureUnit());
+ fboGLAD.addGLEventListener(glel);
+ fboGLAD.display(); // 1st init!
+
+ final FBObject.TextureAttachment texA01 = fboGLAD.getTextureBuffer(GL.GL_FRONT);
+ final Texture tex = new Texture(texA01.getName(), imgSeq.getTextureTarget(),
+ fboGLAD.getWidth(), fboGLAD.getHeight(), fboGLAD.getWidth(), fboGLAD.getHeight(),
+ false /* mustFlipVertically */);
+ imgSeq.addFrame(gl, tex);
+ markStateDirty();
+ } else if( 0 != fboWidth*fboHeight ) {
+ fboGLAD.setSize(fboWidth, fboHeight);
+ fboWidth = 0;
+ fboHeight = 0;
+ } else if( animateGLEL ) {
+ fboGLAD.display();
+ }
+
+ super.drawShape(gl, renderer, sampleCount);
+
+ if( animateGLEL ) {
+ markStateDirty(); // keep on going
+ }
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/ImageSeqButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/ImageSeqButton.java
new file mode 100644
index 000000000..ca6f79448
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/ImageSeqButton.java
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.graph.demos.ui;
+
+import javax.media.opengl.GL2ES2;
+
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.geom.Vertex.Factory;
+import com.jogamp.opengl.util.texture.ImageSequence;
+
+/**
+ * GPU based resolution independent {@link ImageSequence} Button impl
+ */
+public class ImageSeqButton extends TextureSeqButton {
+
+ public ImageSeqButton(final Factory<? extends Vertex> factory, final int renderModes,
+ final float width, final float height, final ImageSequence texSeq) {
+ super(factory, renderModes, width, height, texSeq);
+ setColor(0.95f, 0.95f, 0.95f, 1.0f);
+ setPressedColorMod(1f, 1f, 1f, 0.9f);
+ setToggleOffColorMod(0.8f, 0.8f, 0.8f, 1.0f);
+ setToggleOnColorMod(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+
+ public final void setCurrentIdx(final int idx) {
+ ((ImageSequence)texSeq).setCurrentIdx(idx);
+ markStateDirty();
+ }
+
+ @Override
+ public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount) {
+ super.drawShape(gl, renderer, sampleCount);
+ if( !((ImageSequence)texSeq).getManualStepping() ) {
+ markStateDirty(); // keep on going
+ }
+ };
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/MediaPlayerButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/MediaPlayerButton.java
new file mode 100644
index 000000000..7ec653b62
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/MediaPlayerButton.java
@@ -0,0 +1,131 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.graph.demos.ui;
+
+import javax.media.opengl.GL2ES2;
+
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.geom.Vertex.Factory;
+import com.jogamp.opengl.util.av.GLMediaPlayer;
+import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener;
+import com.jogamp.opengl.util.av.GLMediaPlayer.StreamException;
+import com.jogamp.opengl.util.texture.TextureSequence.TextureFrame;
+
+/**
+ * GPU based resolution independent {@link GLMediaPlayer} Button impl
+ */
+public class MediaPlayerButton extends TextureSeqButton {
+ public boolean verbose = false;
+
+ /**
+ * @param factory
+ * @param renderModes
+ * @param width
+ * @param height
+ * @param mPlayer
+ * @param mPlayerListener
+ */
+ public MediaPlayerButton(final Factory<? extends Vertex> factory, final int renderModes,
+ final float width, final float height,
+ final GLMediaPlayer mPlayer) {
+ super(factory, renderModes, width, height, mPlayer);
+ setColor(0.8f, 0.8f, 0.8f, 1.0f);
+ setPressedColorMod(1.1f, 1.1f, 1.1f, 0.7f);
+ setToggleOffColorMod(0.8f, 0.8f, 0.8f, 1.0f);
+ setToggleOnColorMod(1.0f, 1.0f, 1.0f, 1.0f);
+ setEnabled(false); // data and shader n/a yet
+ }
+
+ /**
+ * Add the default {@link GLMediaEventListener} to {@link #getGLMediaPlayer() this class's GLMediaPlayer}.
+ */
+ public void addDefaultEventListener() {
+ getGLMediaPlayer().addEventListener(defGLMediaEventListener);
+ }
+
+ public final GLMediaPlayer getGLMediaPlayer() { return (GLMediaPlayer)texSeq; }
+
+ private final GLMediaEventListener defGLMediaEventListener = new GLMediaEventListener() {
+ @Override
+ public void newFrameAvailable(GLMediaPlayer ts, TextureFrame newFrame, long when) {
+ // texButton.markStateDirty();
+ }
+
+ @Override
+ public void attributesChanged(final GLMediaPlayer mp, int event_mask, long when) {
+ final GLMediaPlayer mPlayer = (GLMediaPlayer)texSeq;
+ if( verbose ) {
+ System.err.println("MovieCube AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when);
+ System.err.println("MovieCube State: "+mp);
+ }
+ if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) {
+ MediaPlayerButton.this.setEnabled(true); // data and shader is available ..
+ }
+ if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) {
+ // FIXME: mPlayer.resetGLState();
+ }
+ if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) {
+ new Thread() {
+ public void run() {
+ // loop for-ever ..
+ mPlayer.seek(0);
+ mPlayer.play();
+ } }.start();
+ } else if( 0 != ( GLMediaEventListener.EVENT_CHANGE_ERR & event_mask ) ) {
+ final StreamException se = mPlayer.getStreamException();
+ if( null != se ) {
+ se.printStackTrace();
+ }
+ }
+ } };
+
+
+ @Override
+ protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) {
+ ((GLMediaPlayer)texSeq).destroy(gl);
+ }
+
+ @Override
+ public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount) {
+ final GLMediaPlayer mPlayer = (GLMediaPlayer)texSeq;
+ if( GLMediaPlayer.State.Initialized == mPlayer.getState() ) {
+ try {
+ mPlayer.initGL(gl);
+ mPlayer.setAudioVolume( 0f );
+ mPlayer.play();
+ markStateDirty();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ super.drawShape(gl, renderer, sampleCount);
+ markStateDirty(); // keep on going
+ };
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureSeqButton.java
index 5b00d1e3b..2a5212566 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureButton.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureSeqButton.java
@@ -38,19 +38,15 @@ import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.util.texture.TextureSequence;
/**
- * GPU based resolution independent Button impl
+ * GPU based resolution independent {@link TextureSequence} Button impl
*/
-public class TextureButton extends RoundButton {
- private TextureSequence texSeq;
+public class TextureSeqButton extends RoundButton {
+ protected final TextureSequence texSeq;
- public TextureButton(final Factory<? extends Vertex> factory, final int renderModes,
+ public TextureSeqButton(final Factory<? extends Vertex> factory, final int renderModes,
final float width, final float height, final TextureSequence texSeq) {
super(factory, renderModes | Region.COLORTEXTURE_RENDERING_BIT, width, height);
this.texSeq = texSeq;
- setColor(0.8f, 0.8f, 0.8f, 1.0f);
- setPressedColorMod(1.1f, 1.1f, 1.1f, 0.7f);
- setToggleOffColorMod(0.8f, 0.8f, 0.8f, 1.0f);
- setToggleOnColorMod(1.0f, 1.0f, 1.0f, 1.0f);
}
@Override
@@ -58,8 +54,7 @@ public class TextureButton extends RoundButton {
return GLRegion.create(getRenderModes(), texSeq);
}
- public void setTextureSequence(final TextureSequence texSeq) { this.texSeq = texSeq; }
- public TextureSequence getTextureSequence() { return this.texSeq; }
+ public final TextureSequence getTextureSequence() { return this.texSeq; }
@Override
protected void addShapeToRegion(GL2ES2 gl, RegionRenderer renderer) {
@@ -78,7 +73,7 @@ public class TextureButton extends RoundButton {
setRotationOrigin( ctr[0], ctr[1], ctr[2]);
if( DRAW_DEBUG_BOX ) {
- System.err.println("XXX.UIShape.TextureButton: Added Shape: "+shape+", "+box);
+ System.err.println("XXX.UIShape.TextureSeqButton: Added Shape: "+shape+", "+box);
}
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/SingleTextureSeqFrame.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/SingleTextureSeqFrame.java
deleted file mode 100644
index aef48d82c..000000000
--- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/SingleTextureSeqFrame.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.jogamp.opengl.test.junit.jogl.util.texture;
-
-import java.net.URLConnection;
-
-import javax.media.opengl.GL;
-import javax.media.opengl.GLException;
-import javax.media.opengl.GLProfile;
-
-import com.jogamp.common.util.IOUtil;
-import com.jogamp.opengl.util.texture.Texture;
-import com.jogamp.opengl.util.texture.TextureData;
-import com.jogamp.opengl.util.texture.TextureIO;
-import com.jogamp.opengl.util.texture.TextureSequence;
-
-public class SingleTextureSeqFrame implements TextureSequence {
- TextureSequence.TextureFrame frame = null;
- int textureUnit = 0;
- protected int[] texMinMagFilter = { GL.GL_NEAREST, GL.GL_NEAREST };
- protected int[] texWrapST = { GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE };
- final boolean useBuildInTexLookup;
-
- public SingleTextureSeqFrame(boolean useBuildInTexLookup) {
- this.useBuildInTexLookup = useBuildInTexLookup;
- }
-
- public void initGLResources(GL gl, Class<?> context, String imageResourcePath, String imageSuffix) throws GLException {
- if(null == frame) {
- TextureData texData = null;
- try {
- URLConnection urlConn = IOUtil.getResource(context, imageResourcePath);
- if(null != urlConn) {
- texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, imageSuffix);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- final Texture tex = new Texture(gl, texData);
- frame = new TextureSequence.TextureFrame(tex);
- tex.bind(gl);
- gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_MIN_FILTER, texMinMagFilter[0]);
- gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_MAG_FILTER, texMinMagFilter[1]);
- gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_WRAP_S, texWrapST[0]);
- gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_WRAP_T, texWrapST[1]);
- }
- }
-
- public void destroyGLResources(GL gl) {
- if(null != frame) {
- frame.getTexture().destroy(gl);
- frame = null;
- }
- }
-
- public void destroy(GL gl) throws GLException {
- frame.getTexture().destroy(gl);
- frame = null;
- }
-
- @Override
- public int getTextureTarget() {
- return GL.GL_TEXTURE_2D;
- }
-
- @Override
- public int getTextureUnit() {
- return textureUnit;
- }
-
- @Override
- public int[] getTextureMinMagFilter() {
- return texMinMagFilter;
- }
-
- @Override
- public int[] getTextureWrapST() {
- return texWrapST;
- }
-
- @Override
- public boolean isTextureAvailable() { return true; }
-
- @Override
- public TextureSequence.TextureFrame getLastTexture() throws IllegalStateException {
- return frame; // may return null
- }
-
- @Override
- public TextureSequence.TextureFrame getNextTexture(GL gl) throws IllegalStateException {
- return frame;
- }
-
- @Override
- public String getRequiredExtensionsShaderStub() throws IllegalStateException {
- return "// TextTextureSequence: No extensions required\n";
- }
-
- @Override
- public String getTextureSampler2DType() throws IllegalStateException {
- return "sampler2D" ;
- }
-
- private String textureLookupFunctionName = "myTexture2D";
-
- @Override
- public String getTextureLookupFunctionName(String desiredFuncName) throws IllegalStateException {
- if(useBuildInTexLookup) {
- return "texture2D";
- }
- if(null != desiredFuncName && desiredFuncName.length()>0) {
- textureLookupFunctionName = desiredFuncName;
- }
- return textureLookupFunctionName;
- }
-
- @Override
- public String getTextureLookupFragmentShaderImpl() throws IllegalStateException {
- if(useBuildInTexLookup) {
- return "";
- }
- return
- "\n"+
- "vec4 "+textureLookupFunctionName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
- " return texture2D(image, texCoord);\n"+
- "}\n\n";
- }
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java
index 9dc17dce1..86cf4654e 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java
@@ -1,6 +1,7 @@
package com.jogamp.opengl.test.junit.jogl.util.texture;
import java.awt.Frame;
+import java.io.IOException;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
@@ -20,6 +21,7 @@ import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.texture.ImageSequence;
import com.jogamp.opengl.util.texture.TextureIO;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -46,11 +48,15 @@ public class TestTextureSequence01AWT extends UITestCase {
Assert.assertNotNull(frame);
frame.add(glc);
- final SingleTextureSeqFrame texSource = new SingleTextureSeqFrame(useBuildInTexLookup);
+ final ImageSequence texSource = new ImageSequence(0, useBuildInTexLookup);
glc.addGLEventListener(new GLEventListener() {
@Override
public void init(GLAutoDrawable drawable) {
- texSource.initGLResources(drawable.getGL(), TestTextureSequence01AWT.class, "test-ntscP_3-01-160x90.png", TextureIO.PNG);
+ try {
+ texSource.addFrame(drawable.getGL(), TestTextureSequence01AWT.class, "test-ntscP_3-01-160x90.png", TextureIO.PNG);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
@Override
public void dispose(GLAutoDrawable drawable) { }
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01NEWT.java
index c46e334bd..c365b78d6 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01NEWT.java
@@ -1,5 +1,7 @@
package com.jogamp.opengl.test.junit.jogl.util.texture;
+import java.io.IOException;
+
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
@@ -17,6 +19,7 @@ import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.texture.ImageSequence;
import com.jogamp.opengl.util.texture.TextureIO;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -42,11 +45,15 @@ public class TestTextureSequence01NEWT extends UITestCase {
window.setTitle("TestTextureSequence01NEWT");
// Size OpenGL to Video Surface
window.setSize(width, height);
- final SingleTextureSeqFrame texSource = new SingleTextureSeqFrame(useBuildInTexLookup);
+ final ImageSequence texSource = new ImageSequence(0, useBuildInTexLookup);
window.addGLEventListener(new GLEventListener() {
@Override
public void init(GLAutoDrawable drawable) {
- texSource.initGLResources(drawable.getGL(), TestTextureSequence01NEWT.class, "test-ntscP_3-01-160x90.png", TextureIO.PNG);
+ try {
+ texSource.addFrame(drawable.getGL(), TestTextureSequence01NEWT.class, "test-ntscP_3-01-160x90.png", TextureIO.PNG);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
@Override
public void dispose(GLAutoDrawable drawable) { }