commit 32d08f393b17ee73304fd3875c7a7a45a03dd303
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri May 12 13:36:18 2017 +0100

    Beginnings of Stencil App.

diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 1ce435b..562aea2 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -45,6 +45,6 @@
         <activity android:name=".mirror.MirrorActivity"/>
         <activity android:name=".blur.BlurActivity"/>
         <activity android:name=".multiblur.MultiblurActivity"/>
-        <activity android:name=".feedback.FeedbackActivity"/>
+        <activity android:name=".stencil.StencilActivity"/>
     </application>
 </manifest>
diff --git a/src/main/java/org/distorted/examples/TableOfContents.java b/src/main/java/org/distorted/examples/TableOfContents.java
index 8058db4..08a6765 100644
--- a/src/main/java/org/distorted/examples/TableOfContents.java
+++ b/src/main/java/org/distorted/examples/TableOfContents.java
@@ -63,7 +63,7 @@ import org.distorted.examples.wind.WindActivity;
 import org.distorted.examples.mirror.MirrorActivity;
 import org.distorted.examples.blur.BlurActivity;
 import org.distorted.examples.multiblur.MultiblurActivity;
-import org.distorted.examples.feedback.FeedbackActivity;
+import org.distorted.examples.stencil.StencilActivity;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -349,11 +349,11 @@ public class TableOfContents extends ListActivity
 
    {
       final Map<String, Object> item = new HashMap<>();
-      item.put(ITEM_IMAGE, R.drawable.icon_example_feedback);
-      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_feedback));
-      item.put(ITEM_SUBTITLE, getText(R.string.example_feedback_subtitle));
+      item.put(ITEM_IMAGE, R.drawable.icon_example_stencil);
+      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_stencil));
+      item.put(ITEM_SUBTITLE, getText(R.string.example_stencil_subtitle));
       data.add(item);
-      activityMapping.put(i++, FeedbackActivity.class);
+      activityMapping.put(i++, StencilActivity.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});
diff --git a/src/main/java/org/distorted/examples/feedback/FeedbackActivity.java b/src/main/java/org/distorted/examples/feedback/FeedbackActivity.java
deleted file mode 100644
index 9284308..0000000
--- a/src/main/java/org/distorted/examples/feedback/FeedbackActivity.java
+++ /dev/null
@@ -1,71 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// 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.feedback;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-import org.distorted.library.Distorted;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-public class FeedbackActivity extends Activity
-{
-    private FeedbackSurfaceView mView;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-    @Override
-    protected void onCreate(Bundle icicle)
-      {
-      super.onCreate(icicle);
-      mView = new FeedbackSurfaceView(this);
-      setContentView(mView);
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-    
-    @Override
-    protected void onPause() 
-      {
-      mView.onPause();
-      Distorted.onPause();
-      super.onPause();
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-    
-    @Override
-    protected void onResume() 
-      {
-      super.onResume();
-      mView.onResume();
-      }
-    
-///////////////////////////////////////////////////////////////////////////////////////////////////
-    
-    @Override
-    protected void onDestroy() 
-      {
-      Distorted.onDestroy();
-      super.onDestroy();
-      }
-    
-}
diff --git a/src/main/java/org/distorted/examples/feedback/FeedbackRenderer.java b/src/main/java/org/distorted/examples/feedback/FeedbackRenderer.java
deleted file mode 100644
index 4094683..0000000
--- a/src/main/java/org/distorted/examples/feedback/FeedbackRenderer.java
+++ /dev/null
@@ -1,157 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// 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.feedback;
-
-import android.content.res.Resources;
-import android.opengl.GLES30;
-import android.opengl.GLSurfaceView;
-
-import org.distorted.library.Distorted;
-import org.distorted.library.program.DistortedProgram;
-
-import java.io.InputStream;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
-
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.opengles.GL10;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-class FeedbackRenderer implements GLSurfaceView.Renderer
-{
-    private final int BYTESFLOAT = 4;
-    private final int POSITION   = 3;
-
-    private final boolean USEPOINTS=false;
-
-    private GLSurfaceView mView;
-    private DistortedProgram mFeedbackProgram;
-    private int mVertices;
-    private int[] mVBO, mTBO;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-    FeedbackRenderer(GLSurfaceView v)
-      {
-      mView = v;
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-   
-    public void onDrawFrame(GL10 glUnused) 
-      {
-      mFeedbackProgram.useProgram();
-
-      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVBO[0]);
-      GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[0], POSITION, GLES30.GL_FLOAT, false, 0, 0);
-      GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mTBO[0]);
-
-      GLES30.glEnable(GLES30.GL_RASTERIZER_DISCARD);
-      GLES30.glBeginTransformFeedback( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLES);
-      GLES30.glDrawArrays( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLES, 0, mVertices);
-
-      int error = GLES30.glGetError();
-
-      if( error != GLES30.GL_NO_ERROR )
-        {
-        throw new RuntimeException("DrawArrays: glError 0x" + Integer.toHexString(error));
-        }
-
-      GLES30.glEndTransformFeedback();
-      GLES30.glDisable(GLES30.GL_RASTERIZER_DISCARD);
-      GLES30.glFlush();
-
-      Buffer mappedBuffer =  GLES30.glMapBufferRange(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mVertices*POSITION*BYTESFLOAT, GLES30.GL_MAP_READ_BIT);
-      FloatBuffer fb = ((ByteBuffer) mappedBuffer).order(ByteOrder.nativeOrder()).asFloatBuffer();
-      String msg = "";
-
-      for(int i=0; i<mVertices*POSITION; i++) msg += (" "+fb.get(i));
-
-      android.util.Log.d( "Feedback", msg);
-
-      GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER);
-      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-    
-    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
-      { 
-
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-    
-    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
-      {
-      try
-        {
-        Distorted.onCreate(mView.getContext());
-        }
-      catch(Exception ex)
-        {
-        android.util.Log.e("Feedback", ex.getMessage() );
-        }
-
-      final Resources resources = mView.getContext().getResources();
-      final InputStream vertStream = resources.openRawResource(org.distorted.library.R.raw.feedback_vertex_shader);
-      final InputStream fragStream = resources.openRawResource(org.distorted.library.R.raw.feedback_fragment_shader);
-
-      int glsl = 300;
-      String header= "#version 300 es\n";
-      String[] feedback = { "outValue" };
-
-      try
-        {
-        mFeedbackProgram = new DistortedProgram(vertStream,fragStream, header, header, glsl, feedback );
-        }
-      catch(Exception ex)
-        {
-        android.util.Log.e("Feedback", "exception creating feedback program: "+ex.getMessage());
-        }
-
-      float[] floatData = {   1.0f,  4.0f,  9.0f,
-                             16.0f, 25.0f, 36.0f,
-                             49.0f, 64.0f, 81.0f,
-                            100.0f,121.0f,144.0f,
-                              1.0f,  4.0f,  9.0f,
-                             16.0f, 25.0f, 36.0f
-                          };
-
-      mVertices = floatData.length/POSITION;
-      FloatBuffer data = ByteBuffer.allocateDirect(mVertices*POSITION*BYTESFLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
-      data.put(floatData).position(0);
-
-      mVBO = new int[1];
-      GLES30.glGenBuffers(1, mVBO, 0);
-      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVBO[0]);
-      GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, mVertices*POSITION*BYTESFLOAT, data, GLES30.GL_STATIC_DRAW);
-      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
-
-      mTBO = new int[1];
-      GLES30.glGenBuffers(1, mTBO, 0);
-      GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, mTBO[0]);
-      GLES30.glBufferData(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, mVertices*POSITION*BYTESFLOAT, null, GLES30.GL_STATIC_READ);
-      GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0);
-      }
-}
diff --git a/src/main/java/org/distorted/examples/feedback/FeedbackSurfaceView.java b/src/main/java/org/distorted/examples/feedback/FeedbackSurfaceView.java
deleted file mode 100644
index ee059c4..0000000
--- a/src/main/java/org/distorted/examples/feedback/FeedbackSurfaceView.java
+++ /dev/null
@@ -1,42 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// 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.feedback;
-
-import android.app.ActivityManager;
-import android.content.Context;
-import android.content.pm.ConfigurationInfo;
-import android.opengl.GLSurfaceView;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-class FeedbackSurfaceView extends GLSurfaceView
-{
-///////////////////////////////////////////////////////////////////////////////////////////////////
-   
-    public FeedbackSurfaceView(Context context)
-      {
-      super(context);
-      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
-      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
-      setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
-      setRenderer(new FeedbackRenderer(this));
-      }
-}
-
diff --git a/src/main/java/org/distorted/examples/stencil/StencilActivity.java b/src/main/java/org/distorted/examples/stencil/StencilActivity.java
new file mode 100644
index 0000000..95986f3
--- /dev/null
+++ b/src/main/java/org/distorted/examples/stencil/StencilActivity.java
@@ -0,0 +1,71 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.stencil;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import org.distorted.library.Distorted;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class StencilActivity extends Activity
+{
+    private StencilSurfaceView mView;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onCreate(Bundle icicle)
+      {
+      super.onCreate(icicle);
+      mView = new StencilSurfaceView(this);
+      setContentView(mView);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onPause() 
+      {
+      mView.onPause();
+      Distorted.onPause();
+      super.onPause();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onResume() 
+      {
+      super.onResume();
+      mView.onResume();
+      }
+    
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onDestroy() 
+      {
+      Distorted.onDestroy();
+      super.onDestroy();
+      }
+    
+}
diff --git a/src/main/java/org/distorted/examples/stencil/StencilRenderer.java b/src/main/java/org/distorted/examples/stencil/StencilRenderer.java
new file mode 100644
index 0000000..1e46adb
--- /dev/null
+++ b/src/main/java/org/distorted/examples/stencil/StencilRenderer.java
@@ -0,0 +1,182 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.stencil;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.opengl.GLSurfaceView;
+
+import org.distorted.examples.R;
+import org.distorted.library.Distorted;
+import org.distorted.library.DistortedEffects;
+import org.distorted.library.DistortedScreen;
+import org.distorted.library.DistortedTexture;
+import org.distorted.library.EffectNames;
+import org.distorted.library.EffectTypes;
+import org.distorted.library.MeshCubes;
+import org.distorted.library.MeshFlat;
+import org.distorted.library.MeshObject;
+import org.distorted.library.type.Dynamic1D;
+import org.distorted.library.type.Static1D;
+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 StencilRenderer implements GLSurfaceView.Renderer
+{
+    private GLSurfaceView mView;
+    private DistortedScreen mScreen;
+    private DistortedTexture mCubeTex, mFloorTex;
+    private DistortedEffects mCube1Effects, mCube2Effects, mFloorEffects;
+    private MeshObject mCubeMesh, mFloorMesh;
+    private int bmpHeight, bmpWidth;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    StencilRenderer(GLSurfaceView v)
+      {
+      mView = v;
+
+      mCubeMesh  = new MeshCubes(1,1,false);
+      mFloorMesh = new MeshFlat(1,1);
+
+      mCubeTex   = new DistortedTexture(1,1);
+      mFloorTex  = new DistortedTexture(1,1);
+
+      mCube1Effects = new DistortedEffects();
+      mCube2Effects = new DistortedEffects();
+      mFloorEffects = new DistortedEffects();
+
+      mCube2Effects.brightness(new Static1D(0.5f));
+
+      mScreen = new DistortedScreen();
+      mScreen.attach(mCubeTex ,mCube1Effects,mCubeMesh );
+      mScreen.attach(mFloorTex,mFloorEffects,mFloorMesh);
+      mScreen.attach(mCubeTex ,mCube2Effects,mCubeMesh );
+
+      mScreen.glClearColor(1.0f,1.0f,1.0f,1.0f);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+   
+    public void onDrawFrame(GL10 glUnused) 
+      {
+      mScreen.render(System.currentTimeMillis());
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
+      {
+      float cw = mCubeTex.getWidth();
+      float ch = mCubeTex.getHeight();
+      float cd = mCubeTex.getDepth(mCubeMesh);
+
+      float fw = mFloorTex.getWidth();
+      float fh = mFloorTex.getHeight();
+      float fd = mFloorTex.getDepth(mFloorMesh);
+
+      float cubeScale = 0.4f*(width>height ? height/ch:width/cw);
+      float floorScale= 0.8f*(width>height ? height/fh:width/fw);
+
+      Static3D cubeCenter = new Static3D(cw/2,ch  ,-cd/2);
+      Static3D floorCenter= new Static3D(fw/2,fh/2,-fd/2);
+
+      Static3D axisX = new Static3D(1,0,0);
+      Static3D axisY = new Static3D(0,1,0);
+      Static3D axisZ = new Static3D(0,0,1);
+
+      Dynamic1D rotDyn = new Dynamic1D(5000,0.0f);
+      rotDyn.setMode(Dynamic1D.MODE_JUMP);
+      rotDyn.add(new Static1D(  0));
+      rotDyn.add(new Static1D(360));
+
+      float angle = 30.0f;
+
+      Static1D rotSt1 = new Static1D(angle);
+      Static1D rotSt2 = new Static1D(angle-90.0f);
+
+      mCube1Effects.abortEffects(EffectTypes.MATRIX);
+      mCube1Effects.move( new Static3D( (width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2) );
+      mCube1Effects.scale(cubeScale);
+      mCube1Effects.rotate(rotSt1, axisX, cubeCenter);
+      mCube1Effects.rotate(rotDyn, axisY, cubeCenter);
+
+      mCube2Effects.abortEffects(EffectTypes.MATRIX);
+      mCube2Effects.move( new Static3D( (width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2) );
+      mCube2Effects.scale(cubeScale);
+      mCube2Effects.rotate(rotSt1, axisX, cubeCenter);
+      mCube2Effects.rotate(rotDyn, axisY, cubeCenter);
+      mCube2Effects.scale(new Static3D(1,-1,1) );
+      mCube2Effects.move( new Static3D( 0, -2*ch , 0) );
+
+      mFloorEffects.abortEffects(EffectTypes.MATRIX);
+      mFloorEffects.move( new Static3D( (width-floorScale*fw)/2 ,height/2-floorScale*fh/2, floorScale*fd/2) );
+      mFloorEffects.scale(floorScale);
+      mFloorEffects.rotate(rotSt2, axisX, floorCenter);
+      mFloorEffects.rotate(rotDyn, axisZ, floorCenter);
+
+      mScreen.resize(width, height);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
+      {
+      InputStream is = mView.getContext().getResources().openRawResource(R.raw.cat);
+      Bitmap bitmap;
+
+      try
+        {
+        bitmap = BitmapFactory.decodeStream(is);
+        }
+      finally
+        {
+        try
+          {
+          is.close();
+          }
+        catch(IOException e) { }
+        }
+
+      bmpHeight = bitmap.getHeight();
+      bmpWidth  = bitmap.getWidth();
+
+      mCubeTex.setTexture(bitmap);
+      mFloorTex.setColor(0xff000000);  // ARGB
+
+      DistortedEffects.enableEffect(EffectNames.BRIGHTNESS);
+
+      try
+        {
+        Distorted.onCreate(mView.getContext());
+        }
+      catch(Exception ex)
+        {
+        android.util.Log.e("Stencil", ex.getMessage() );
+        }
+      }
+}
diff --git a/src/main/java/org/distorted/examples/stencil/StencilSurfaceView.java b/src/main/java/org/distorted/examples/stencil/StencilSurfaceView.java
new file mode 100644
index 0000000..39ff359
--- /dev/null
+++ b/src/main/java/org/distorted/examples/stencil/StencilSurfaceView.java
@@ -0,0 +1,42 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.stencil;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ConfigurationInfo;
+import android.opengl.GLSurfaceView;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class StencilSurfaceView extends GLSurfaceView
+{
+///////////////////////////////////////////////////////////////////////////////////////////////////
+   
+    public StencilSurfaceView(Context context)
+      {
+      super(context);
+      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
+      setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
+      setRenderer(new StencilRenderer(this));
+      }
+}
+
diff --git a/src/main/res/drawable-hdpi/icon_example_feedback.png b/src/main/res/drawable-hdpi/icon_example_feedback.png
deleted file mode 100644
index 3d73dbc..0000000
Binary files a/src/main/res/drawable-hdpi/icon_example_feedback.png and /dev/null differ
diff --git a/src/main/res/drawable-hdpi/icon_example_stencil.png b/src/main/res/drawable-hdpi/icon_example_stencil.png
new file mode 100644
index 0000000..3d73dbc
Binary files /dev/null and b/src/main/res/drawable-hdpi/icon_example_stencil.png differ
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 4c49474..05a8fd8 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -141,8 +141,8 @@
     <string name="example_blur_subtitle">Postprocessing effect: Blur.</string>
     <string name="example_multiblur">Multiblur</string>
     <string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</string>
-    <string name="example_feedback">Transform Feedback</string>
-    <string name="example_feedback_subtitle">Transform Feedback test.</string>
+    <string name="example_stencil">Stencil Buffer</string>
+    <string name="example_stencil_subtitle">Implement the classic stencil example from https://open.gl/depthstencils</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>
