diff options
author | Sven Gothel <[email protected]> | 2008-11-27 22:56:54 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-11-27 22:56:54 +0000 |
commit | 67a26a661d0230aa7a30535fc7c867984f544c4c (patch) | |
tree | d1e6e39e1ed9a47e32a9aff6e811d6a019aa0573 /src/demos | |
parent | 632488cdece479c7515e38efeb7594813b85846b (diff) |
Adding OpenMAX ES2 demo
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@300 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos')
-rwxr-xr-x | src/demos/es2/openmax/MovieSimple.java | 301 | ||||
-rwxr-xr-x | src/demos/es2/openmax/shader/bin/nvidia/moviesimple.bfp | bin | 0 -> 684 bytes | |||
-rwxr-xr-x | src/demos/es2/openmax/shader/bin/nvidia/moviesimple.bvp | bin | 0 -> 940 bytes | |||
-rw-r--r-- | src/demos/es2/openmax/shader/moviesimple.fp | 21 | ||||
-rw-r--r-- | src/demos/es2/openmax/shader/moviesimple.vp | 22 | ||||
-rwxr-xr-x | src/demos/es2/openmax/shader/scripts/nvidia-apx/glslc-ff.bat | 9 |
6 files changed, 353 insertions, 0 deletions
diff --git a/src/demos/es2/openmax/MovieSimple.java b/src/demos/es2/openmax/MovieSimple.java new file mode 100755 index 0000000..811868d --- /dev/null +++ b/src/demos/es2/openmax/MovieSimple.java @@ -0,0 +1,301 @@ + +package demos.es2.openmax; + +import javax.media.opengl.*; +import javax.media.opengl.util.*; +import javax.media.opengl.glsl.*; + +import com.sun.javafx.media.video.openmax.*; + +import java.nio.*; +import java.net.*; + +import com.sun.javafx.newt.*; + +public class MovieSimple implements MouseListener, GLEventListener { + + private GLWindow window; + private boolean quit = false; + private boolean rotate = false; + private float zoom = -2.5f; + private float ang = 0f; + private long startTime; + private long curTime; + private String stream; + + public void mouseClicked(MouseEvent e) { + switch(e.getClickCount()) { + case 2: + quit=true; + break; + } + } + public void mouseEntered(MouseEvent e) { + } + public void mouseExited(MouseEvent e) { + } + public void mousePressed(MouseEvent e) { + } + public void mouseReleased(MouseEvent e) { + rotate = false; + zoom = -2.5f; + } + public void mouseMoved(MouseEvent e) { + } + public void mouseDragged(MouseEvent e) { + rotate = true; + zoom = -5; + } + + public MovieSimple(String stream) { + this.stream = stream ; + } + + private void run() { + System.err.println("MovieSimple.run()"); + GLProfile.setProfileGL2ES2(); + try { + GLCapabilities caps = new GLCapabilities(); + // For emulation library, use 16 bpp + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + caps.setDepthBits(16); + + window = GLWindow.create(caps); + + window.addMouseListener(this); + window.addGLEventListener(this); + // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default + // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current .. + + // Size OpenGL to Video Surface + window.setFullscreen(true); + window.setVisible(true); + + startTime = System.currentTimeMillis(); + while (!quit) { + window.display(); + } + + // Shut things down cooperatively + if(null!=movie) { + movie.dispose(); + movie=null; + } + window.close(); + window.getFactory().shutdown(); + System.out.println("MovieSimple shut down cleanly."); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + ShaderState st; + PMVMatrix pmvMatrix; + + private void initShader(GL2ES2 gl) { + int tmpI; + + // Create & Compile the shader objects + ShaderCode rsVp = ShaderCode.create(gl, gl.GL_VERTEX_SHADER, 1, MovieSimple.class, + "shader", "shader/bin", "moviesimple"); + ShaderCode rsFp = ShaderCode.create(gl, gl.GL_FRAGMENT_SHADER, 1, MovieSimple.class, + "shader", "shader/bin", "moviesimple"); + + // Create & Link the shader program + ShaderProgram sp = new ShaderProgram(); + sp.add(rsVp); + sp.add(rsFp); + if(!sp.link(gl, System.err)) { + throw new GLException("Couldn't link program: "+sp); + } + + // Let's manage all our states using ShaderState. + st = new ShaderState(); + st.attachShaderProgram(gl, sp); + } + + OMXMoviePlayerImpl movie=null; + + public void init(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + System.err.println("Entering initialization"); + System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); + System.err.println("GL_EXTENSIONS:"); + System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS)); + + try { + movie = new OMXMoviePlayerImpl(new URL(stream)); + } catch (MalformedURLException mue) { mue.printStackTrace(); } + if(null!=movie) { + movie.play(); + } + + if(gl.isGLES2()) { + pmvMatrix = gl.getGLES2().getPMVMatrix(); + } else { + pmvMatrix = new PMVMatrix(); + } + + initShader(gl); + + // Push the 1st uniform down the path + st.glUseProgram(gl, true); + + pmvMatrix.glMatrixMode(gl.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glMatrixMode(gl.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + + if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) { + throw new GLException("Error setting PMVMatrix in shader: "+st); + } + if(!st.glUniform(gl, new GLUniformData("mgl_ActiveTexture", 0))) { + throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); + } + gl.glActiveTexture(GL.GL_TEXTURE0); + + float aspect = 16.0f/9.0f; + float xs=1f, ys=1f; // scale object + float ss=1f, ts=1f; // scale tex-coord + + if(true) { + xs = aspect; // b > h + ys = 1f; // b > h + } else { + ss = 1f; // b > h + ts = 1f/aspect; // b > h + } + + // Allocate vertex array + GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + { + // Fill them up + FloatBuffer verticeb = (FloatBuffer)vertices.getBuffer(); + verticeb.put(-1f*xs); verticeb.put( -1f*ys); verticeb.put( 0); + verticeb.put(-1f*xs); verticeb.put( 1f*ys); verticeb.put( 0); + verticeb.put( 1f*xs); verticeb.put( -1f*ys); verticeb.put( 0); + verticeb.put( 1f*xs); verticeb.put( 1f*ys); verticeb.put( 0); + } + vertices.seal(gl, true); + + // Allocate texcoord array + GLArrayDataServer texcoord = GLArrayDataServer.createGLSL("mgl_MultiTexCoord", 2, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + { + // Fill them up + FloatBuffer texcoordb = (FloatBuffer)texcoord.getBuffer(); + texcoordb.put( 0f*ss); texcoordb.put( 0f*ts); + texcoordb.put( 0f*ss); texcoordb.put( 1f*ts); + texcoordb.put( 1f*ss); texcoordb.put( 0f*ts); + texcoordb.put( 1f*ss); texcoordb.put( 1f*ts); + } + texcoord.seal(gl, true); + + GLArrayDataServer colors = GLArrayDataServer.createGLSL("mgl_Color", 4, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + { + // Fill them up + FloatBuffer colorb = (FloatBuffer)colors.getBuffer(); + colorb.put( 0); colorb.put( 0); colorb.put( 0); colorb.put( 1); + colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put( 1); + colorb.put( 0); colorb.put( 0); colorb.put( 0); colorb.put( 1); + colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put( 1); + } + colors.seal(gl, true); + + // OpenGL Render Settings + gl.glClearColor(0.2f, 0.2f, 0.2f, 1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + + st.glUseProgram(gl, false); + + // Let's show the completed shader state .. + System.out.println(st); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + st.glUseProgram(gl, true); + + // Set location in front of camera + pmvMatrix.glMatrixMode(GL2ES2.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f); + //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + + pmvMatrix.glMatrixMode(gl.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, zoom); + + GLUniformData ud = st.getUniform("mgl_PMVMatrix"); + if(null!=ud) { + // same data object + st.glUniform(gl, ud); + } + + st.glUseProgram(gl, false); + } + + public void display(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + st.glUseProgram(gl, true); + + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); + + if(rotate) { + curTime = System.currentTimeMillis(); + ang = ((float) (curTime - startTime) * 360.0f) / 8000.0f; + } + + if(rotate || zoom!=0f) { + pmvMatrix.glMatrixMode(gl.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, zoom); + pmvMatrix.glRotatef(ang, 0, 0, 1); + // pmvMatrix.glRotatef(ang, 0, 1, 0); + + GLUniformData ud = st.getUniform("mgl_PMVMatrix"); + if(null!=ud) { + // same data object + st.glUniform(gl, ud); + } + + if(!rotate) { + zoom=0f; + } + } + + + com.sun.opengl.util.texture.Texture tex = null; + if(null!=movie) { + tex=movie.lockTexture(); + if(null!=tex) { + tex.enable(); + tex.bind(); + } + } + + // Draw a square + gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4); + + if(null!=tex) { + gl.glFinish(); // fake sync + tex.disable(); + movie.unlockTexture(); + } + + st.glUseProgram(gl, false); + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + + public static void main(String[] args) { + String fname="file:///Storage Card/resources/a.mp4"; + if(args.length>0) fname=args[0]; + new MovieSimple(fname).run(); + System.exit(0); + } +} diff --git a/src/demos/es2/openmax/shader/bin/nvidia/moviesimple.bfp b/src/demos/es2/openmax/shader/bin/nvidia/moviesimple.bfp Binary files differnew file mode 100755 index 0000000..97a6980 --- /dev/null +++ b/src/demos/es2/openmax/shader/bin/nvidia/moviesimple.bfp diff --git a/src/demos/es2/openmax/shader/bin/nvidia/moviesimple.bvp b/src/demos/es2/openmax/shader/bin/nvidia/moviesimple.bvp Binary files differnew file mode 100755 index 0000000..2ca3dff --- /dev/null +++ b/src/demos/es2/openmax/shader/bin/nvidia/moviesimple.bvp diff --git a/src/demos/es2/openmax/shader/moviesimple.fp b/src/demos/es2/openmax/shader/moviesimple.fp new file mode 100644 index 0000000..c711641 --- /dev/null +++ b/src/demos/es2/openmax/shader/moviesimple.fp @@ -0,0 +1,21 @@ + +#ifdef GL_ES + #define MEDIUMP mediump + #define HIGHP highp +#else + #define MEDIUMP + #define HIGHP +#endif + +uniform sampler2D mgl_ActiveTexture; +varying HIGHP vec4 mgl_texCoord; +varying HIGHP vec4 frontColor; + +void main (void) +{ + vec4 texColor = texture2D(mgl_ActiveTexture, mgl_texCoord.st); + + // mix frontColor with texture .. + gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a); +} + diff --git a/src/demos/es2/openmax/shader/moviesimple.vp b/src/demos/es2/openmax/shader/moviesimple.vp new file mode 100644 index 0000000..0b78eb9 --- /dev/null +++ b/src/demos/es2/openmax/shader/moviesimple.vp @@ -0,0 +1,22 @@ + +#ifdef GL_ES + #define MEDIUMP mediump + #define HIGHP highp +#else + #define MEDIUMP + #define HIGHP +#endif + +uniform MEDIUMP mat4 mgl_PMVMatrix[2]; +attribute HIGHP vec4 mgl_Vertex; +attribute HIGHP vec4 mgl_Color; +attribute HIGHP vec4 mgl_MultiTexCoord; +varying HIGHP vec4 frontColor; +varying HIGHP vec4 mgl_texCoord; + +void main(void) +{ + frontColor=mgl_Color; + mgl_texCoord = mgl_MultiTexCoord; + gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex; +} diff --git a/src/demos/es2/openmax/shader/scripts/nvidia-apx/glslc-ff.bat b/src/demos/es2/openmax/shader/scripts/nvidia-apx/glslc-ff.bat new file mode 100755 index 0000000..a93f43c --- /dev/null +++ b/src/demos/es2/openmax/shader/scripts/nvidia-apx/glslc-ff.bat @@ -0,0 +1,9 @@ +REM +REM You have to call it from the 'shader' directory, e.g.: +REM scripts\nvidia-apx\glslc-ff.bat +REM +IF !"%JOGLDIR%"==""! GOTO YESPATH +set JOGLDIR=..\lib +:YESPATH + +java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar javax.media.opengl.sdk.glsl.CompileShaderNVidia moviesimple.vp moviesimple.fp |