commit 03a2fd30c6b2883b8e5aa17c3b9615fb917a8f04
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri Dec 16 14:12:27 2016 +0000

    First attempt at the 'Mirror' app.

diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 653a28a..4d42239 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -42,5 +42,6 @@
         <activity android:name=".flag.FlagActivity"/>
         <activity android:name=".wind.WindActivity"/>
         <activity android:name=".aroundtheworld.AroundTheWorldActivity"/>
+        <activity android:name=".mirror.MirrorActivity"/>
     </application>
 </manifest>
diff --git a/src/main/java/org/distorted/examples/TableOfContents.java b/src/main/java/org/distorted/examples/TableOfContents.java
index 98770e4..8014050 100644
--- a/src/main/java/org/distorted/examples/TableOfContents.java
+++ b/src/main/java/org/distorted/examples/TableOfContents.java
@@ -60,6 +60,7 @@ import org.distorted.examples.plainmonalisa.PlainMonaLisaActivity;
 import org.distorted.examples.save.SaveActivity;
 import org.distorted.examples.flag.FlagActivity;
 import org.distorted.examples.wind.WindActivity;
+import org.distorted.examples.mirror.MirrorActivity;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -316,6 +317,15 @@ public class TableOfContents extends ListActivity
       activityMapping.put(i++, AroundTheWorldActivity.class);
    }
 
+   {
+      final Map<String, Object> item = new HashMap<>();
+      item.put(ITEM_IMAGE, R.drawable.icon_example_mirror);
+      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_mirror));
+      item.put(ITEM_SUBTITLE, getText(R.string.example_mirror_subtitle));
+      data.add(item);
+      activityMapping.put(i++, MirrorActivity.class);
+   }
+
    final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
    setListAdapter(dataAdapter);  
       
diff --git a/src/main/java/org/distorted/examples/mirror/MirrorActivity.java b/src/main/java/org/distorted/examples/mirror/MirrorActivity.java
new file mode 100644
index 0000000..091c6d6
--- /dev/null
+++ b/src/main/java/org/distorted/examples/mirror/MirrorActivity.java
@@ -0,0 +1,98 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.examples.mirror;
+
+import android.app.Activity;
+import android.opengl.GLSurfaceView;
+import android.os.Bundle;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+
+import org.distorted.examples.R;
+import org.distorted.library.Distorted;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class MirrorActivity extends Activity implements OnSeekBarChangeListener
+{
+    @Override
+    protected void onCreate(Bundle icicle) 
+      {
+      super.onCreate(icicle);
+      setContentView(R.layout.mirrorlayout);
+       
+      SeekBar bar = (SeekBar)findViewById(R.id.mirrorSeek);
+      bar.setOnSeekBarChangeListener(this);
+      bar.setProgress(100);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onPause() 
+      {
+      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.mirrorSurfaceView);
+      view.onPause();
+      super.onPause();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onResume() 
+      {
+      super.onResume();
+      MirrorSurfaceView view = (MirrorSurfaceView) this.findViewById(R.id.mirrorSurfaceView);
+      view.onResume();
+      view.getRenderer().onResume();
+      }
+ 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onDestroy() 
+      {
+      Distorted.onDestroy();  
+      super.onDestroy();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
+      {
+      switch (bar.getId()) 
+        {
+        case R.id.mirrorSeek: MirrorSurfaceView view = (MirrorSurfaceView) this.findViewById(R.id.mirrorSurfaceView);
+                              view.getRenderer().setPosition(progress);
+                              break;
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onStartTrackingTouch(SeekBar bar) { }
+    
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onStopTrackingTouch(SeekBar bar)  { }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+}
diff --git a/src/main/java/org/distorted/examples/mirror/MirrorRenderer.java b/src/main/java/org/distorted/examples/mirror/MirrorRenderer.java
new file mode 100644
index 0000000..93fa760
--- /dev/null
+++ b/src/main/java/org/distorted/examples/mirror/MirrorRenderer.java
@@ -0,0 +1,178 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.examples.mirror;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.opengl.GLES20;
+import android.opengl.GLSurfaceView;
+
+import org.distorted.examples.R;
+import org.distorted.library.Distorted;
+import org.distorted.library.DistortedEffects;
+import org.distorted.library.DistortedFramebuffer;
+import org.distorted.library.DistortedTexture;
+import org.distorted.library.GridFlat;
+import org.distorted.library.type.Dynamic3D;
+import org.distorted.library.type.Static3D;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class MirrorRenderer implements GLSurfaceView.Renderer
+{
+   private static final float SCALE = 0.5f;
+
+   private GLSurfaceView mView;
+   private DistortedEffects mEffectsMirror, mEffectsGirl, mEffectsOffscreen, mEffectsNull;
+   private DistortedTexture mTextureMirror, mTextureGirl;
+   private DistortedFramebuffer mScreen, mOffScreen1, mOffScreen2;
+   private GridFlat mQuad;
+   private Static3D mGirlPosition;
+   private Dynamic3D mGirlDyn;
+
+   private int mMirrorW, mMirrorH, mGirlW, mGirlH;
+   private int mScreenW, mScreenH;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   MirrorRenderer(GLSurfaceView view)
+      { 
+      mView    = view;
+      mQuad    = new GridFlat(1,1);
+      mScreen  = new DistortedFramebuffer(0);
+
+      mEffectsMirror   = new DistortedEffects();
+      mEffectsGirl     = new DistortedEffects();
+      mEffectsOffscreen= new DistortedEffects();
+      mEffectsNull     = new DistortedEffects();
+
+      mGirlPosition = new Static3D(0,0,0);
+      mGirlDyn      = new Dynamic3D();
+      mGirlDyn.add(mGirlPosition);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   void setPosition(int pos)
+      {
+      mGirlPosition.set1(pos*mScreenW / 100.0f);
+      }
+   
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   public void onResume()
+     {
+     mScreenW = 0;
+     mScreenH = 0;
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   public void onDrawFrame(GL10 glUnused) 
+      {
+      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
+
+      long time = System.currentTimeMillis();
+
+      mOffScreen1.renderTo( mTextureMirror, mQuad, mEffectsMirror   , time );
+      mOffScreen1.renderTo( mOffScreen2   , mQuad, mEffectsOffscreen, time );
+      mOffScreen1.renderTo( mTextureGirl  , mQuad, mEffectsGirl     , time );
+      mOffScreen2.renderTo( mOffScreen1   , mQuad, mEffectsNull     , time );
+      mScreen.renderTo    ( mOffScreen1   , mQuad, mEffectsMirror   , time );
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+   public void onSurfaceChanged(GL10 glUnused, int width, int height) 
+      {
+      if( mScreenW!=width || mScreenH!=height)
+        {
+        mScreenW = width;
+        mScreenH = height;
+
+        mOffScreen1 = new DistortedFramebuffer(mScreenW,mScreenH);
+        mOffScreen2 = new DistortedFramebuffer( (int)(SCALE*mScreenW), (int)(SCALE*mScreenH) );
+
+        mEffectsGirl.abortAllEffects();
+        mEffectsMirror.abortAllEffects();
+        mEffectsOffscreen.abortAllEffects();
+
+        mEffectsMirror.scale( new Static3D( (float)mScreenW/mMirrorW, (float)mScreenH/mMirrorH, 1.0f) );
+        mEffectsOffscreen.move( new Static3D( mScreenW/10, mScreenH/10, 0) );
+        mEffectsGirl.move(mGirlDyn);
+        mGirlPosition.set2(mScreenH*0.9f);
+
+        mScreen.resize(mScreenW,mScreenH);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
+      {
+      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+
+      InputStream isM = mView.getContext().getResources().openRawResource(R.raw.mirror);
+      InputStream isG = mView.getContext().getResources().openRawResource(R.raw.face);
+
+      Bitmap bitmapM, bitmapG;
+
+      try
+        {
+        bitmapM = BitmapFactory.decodeStream(isM);
+        bitmapG = BitmapFactory.decodeStream(isG);
+        }
+      finally
+        {
+        try
+          {
+          isM.close();
+          isG.close();
+          }
+        catch(IOException e) { }
+        }
+
+      mMirrorW = bitmapM.getWidth();
+      mMirrorH = bitmapM.getHeight();
+      mGirlW   = bitmapG.getWidth();
+      mGirlH   = bitmapG.getHeight();
+
+      mTextureMirror = new DistortedTexture(mMirrorW,mMirrorH);
+      mTextureGirl   = new DistortedTexture(mGirlW, mGirlH);
+
+      mTextureMirror.setTexture(bitmapM);
+      mTextureGirl.setTexture(bitmapG);
+
+      try
+        {
+        Distorted.onSurfaceCreated(mView.getContext());
+        }
+      catch(Exception ex)
+        {
+        android.util.Log.e("Mirror", ex.getMessage() );
+        }
+      }
+}
diff --git a/src/main/java/org/distorted/examples/mirror/MirrorSurfaceView.java b/src/main/java/org/distorted/examples/mirror/MirrorSurfaceView.java
new file mode 100644
index 0000000..2400610
--- /dev/null
+++ b/src/main/java/org/distorted/examples/mirror/MirrorSurfaceView.java
@@ -0,0 +1,52 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.examples.mirror;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+import android.util.AttributeSet;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class MirrorSurfaceView extends GLSurfaceView
+{
+    private MirrorRenderer mRenderer;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public MirrorSurfaceView(Context c, AttributeSet attrs)
+      {
+      super(c, attrs);
+
+      if(!isInEditMode())
+        {
+        setEGLContextClientVersion(2);
+        mRenderer = new MirrorRenderer(this);
+        setRenderer(mRenderer);
+        }
+      }
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public MirrorRenderer getRenderer()
+      {
+      return mRenderer;
+      }
+}
+
diff --git a/src/main/res/drawable-hdpi/icon_example_fbo.png b/src/main/res/drawable-hdpi/icon_example_fbo.png
index fbdeded..5415d56 100644
Binary files a/src/main/res/drawable-hdpi/icon_example_fbo.png and b/src/main/res/drawable-hdpi/icon_example_fbo.png differ
diff --git a/src/main/res/drawable-hdpi/icon_example_mirror.png b/src/main/res/drawable-hdpi/icon_example_mirror.png
new file mode 100644
index 0000000..5415d56
Binary files /dev/null and b/src/main/res/drawable-hdpi/icon_example_mirror.png differ
diff --git a/src/main/res/layout/mirrorlayout.xml b/src/main/res/layout/mirrorlayout.xml
new file mode 100644
index 0000000..cd90812
--- /dev/null
+++ b/src/main/res/layout/mirrorlayout.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical" >
+
+    <org.distorted.examples.mirror.MirrorSurfaceView
+        android:id="@+id/mirrorSurfaceView"
+        android:layout_width="fill_parent"
+        android:layout_height="0dp"
+        android:layout_weight="1" />
+
+    <LinearLayout
+        android:id="@+id/linearLayout1"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center|fill_horizontal"
+        android:orientation="horizontal"
+        android:paddingBottom="10dp"
+        android:paddingTop="10dp" >
+
+        <SeekBar
+            android:id="@+id/mirrorSeek"
+            android:layout_weight="1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:paddingLeft="10dp"
+            android:paddingRight="10dp" />
+
+    </LinearLayout>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/src/main/res/raw/fbo.png b/src/main/res/raw/fbo.png
deleted file mode 100644
index 2b54f94..0000000
Binary files a/src/main/res/raw/fbo.png and /dev/null differ
diff --git a/src/main/res/raw/mirror.jpg b/src/main/res/raw/mirror.jpg
new file mode 100644
index 0000000..fd6effc
Binary files /dev/null and b/src/main/res/raw/mirror.jpg differ
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 6e002a2..cd9b059 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -124,6 +124,8 @@
     <string name="example_wind_subtitle">A couple of effects put together to create an effect of a waving flag.</string>
     <string name="example_aroundtheworld">Around the World</string>
     <string name="example_aroundtheworld_subtitle">Combine several effects to change facial features.</string>
+    <string name="example_mirror">Mirror</string>
+    <string name="example_mirror_subtitle">Ping-pong between offscreen buffers to achieve the \'infinite mirror\' effect.</string>
 
     <string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string>
     <string name="example_rotate_toast">Rotate the scene by swiping the screen</string>
