commit cb9d104d59457551d57e403d4fc4922a0769f31e
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Wed Jun 28 13:00:39 2017 +0100

    New 'Glow' app.

diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index c294a50..3aad5c0 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -46,6 +46,7 @@
         <activity android:name=".blur.BlurActivity"/>
         <activity android:name=".multiblur.MultiblurActivity"/>
         <activity android:name=".stencil.StencilActivity"/>
+        <activity android:name=".glow.GlowActivity"/>
         <activity android:name=".movingglow.MovingGlowActivity"/>
     </application>
 </manifest>
diff --git a/src/main/java/org/distorted/examples/TableOfContents.java b/src/main/java/org/distorted/examples/TableOfContents.java
index 3dc6fc3..7804bd0 100644
--- a/src/main/java/org/distorted/examples/TableOfContents.java
+++ b/src/main/java/org/distorted/examples/TableOfContents.java
@@ -64,6 +64,7 @@ import org.distorted.examples.mirror.MirrorActivity;
 import org.distorted.examples.blur.BlurActivity;
 import org.distorted.examples.multiblur.MultiblurActivity;
 import org.distorted.examples.stencil.StencilActivity;
+import org.distorted.examples.glow.GlowActivity;
 import org.distorted.examples.movingglow.MovingGlowActivity;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -357,9 +358,18 @@ public class TableOfContents extends ListActivity
       activityMapping.put(i++, StencilActivity.class);
    }
 
-  {
+   {
       final Map<String, Object> item = new HashMap<>();
       item.put(ITEM_IMAGE, R.drawable.icon_example_glow);
+      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_glow));
+      item.put(ITEM_SUBTITLE, getText(R.string.example_glow_subtitle));
+      data.add(item);
+      activityMapping.put(i++, GlowActivity.class);
+   }
+
+   {
+      final Map<String, Object> item = new HashMap<>();
+      item.put(ITEM_IMAGE, R.drawable.icon_example_movingglow);
       item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_moving_glow));
       item.put(ITEM_SUBTITLE, getText(R.string.example_moving_glow_subtitle));
       data.add(item);
diff --git a/src/main/java/org/distorted/examples/blur/BlurActivity.java b/src/main/java/org/distorted/examples/blur/BlurActivity.java
index 5e72446..3a94a06 100644
--- a/src/main/java/org/distorted/examples/blur/BlurActivity.java
+++ b/src/main/java/org/distorted/examples/blur/BlurActivity.java
@@ -41,13 +41,9 @@ public class BlurActivity extends Activity  implements OnSeekBarChangeListener
     protected void onCreate(Bundle icicle) 
       {
       super.onCreate(icicle);
-      
       setContentView(R.layout.blurlayout);
-
       textBlur = (TextView)findViewById(R.id.blurText);
-
       SeekBar bar = (SeekBar)findViewById(R.id.blurSeek);
-
       bar.setOnSeekBarChangeListener(this);
       bar.setProgress(50);
       }
@@ -69,7 +65,6 @@ public class BlurActivity extends Activity  implements OnSeekBarChangeListener
     protected void onResume() 
       {
       super.onResume();
-      
       GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.blurSurfaceView);
       view.onResume();
       }
diff --git a/src/main/java/org/distorted/examples/glow/GlowActivity.java b/src/main/java/org/distorted/examples/glow/GlowActivity.java
new file mode 100644
index 0000000..1370f13
--- /dev/null
+++ b/src/main/java/org/distorted/examples/glow/GlowActivity.java
@@ -0,0 +1,102 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.glow;
+
+import android.app.Activity;
+import android.opengl.GLSurfaceView;
+import android.os.Bundle;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+import org.distorted.examples.R;
+import org.distorted.library.main.Distorted;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class GlowActivity extends Activity implements SeekBar.OnSeekBarChangeListener
+{
+    private TextView textGlow;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onCreate(Bundle savedState)
+      {
+      super.onCreate(savedState);
+      setContentView(R.layout.glowlayout);
+      textGlow = (TextView)findViewById(R.id.glowText);
+      SeekBar bar = (SeekBar)findViewById(R.id.glowSeek);
+      bar.setOnSeekBarChangeListener(this);
+      bar.setProgress(50);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onPause() 
+      {
+      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.glowSurfaceView);
+      view.onPause();
+      Distorted.onPause();
+      super.onPause();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onResume() 
+      {
+      super.onResume();
+      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.glowSurfaceView);
+      view.onResume();
+      }
+ 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onDestroy() 
+      {
+      Distorted.onDestroy();  
+      super.onDestroy();
+      }
+
+///////////////////////////////////////////////////////////////////
+
+    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
+      {
+      GlowSurfaceView view = (GlowSurfaceView) this.findViewById(R.id.glowSurfaceView);
+
+      switch (bar.getId())
+        {
+        case R.id.glowSeek: int level = view.getRenderer().setGlow(progress);
+                            textGlow.setText(getString(R.string.glow_placeholder,level));
+                            break;
+        }
+      }
+
+///////////////////////////////////////////////////////////////////
+
+    public void onStartTrackingTouch(SeekBar bar) { }
+
+///////////////////////////////////////////////////////////////////
+
+    public void onStopTrackingTouch(SeekBar bar)  { }
+
+}
diff --git a/src/main/java/org/distorted/examples/glow/GlowRenderer.java b/src/main/java/org/distorted/examples/glow/GlowRenderer.java
new file mode 100644
index 0000000..238cf54
--- /dev/null
+++ b/src/main/java/org/distorted/examples/glow/GlowRenderer.java
@@ -0,0 +1,146 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.glow;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.opengl.GLSurfaceView;
+
+import org.distorted.examples.R;
+import org.distorted.library.effect.MatrixEffectMove;
+import org.distorted.library.effect.MatrixEffectScale;
+import org.distorted.library.effect.PostprocessEffectGlow;
+import org.distorted.library.main.Distorted;
+import org.distorted.library.main.DistortedEffects;
+import org.distorted.library.main.DistortedScreen;
+import org.distorted.library.main.DistortedTexture;
+import org.distorted.library.main.MeshFlat;
+import org.distorted.library.type.Static1D;
+import org.distorted.library.type.Static3D;
+import org.distorted.library.type.Static4D;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class GlowRenderer implements GLSurfaceView.Renderer
+{
+   private static final int LEAF_SIZE = 100;
+
+   private GLSurfaceView mView;
+   private DistortedTexture mLeaf;
+   private DistortedScreen mScreen;
+   private int mRootW, mRootH;
+   private Static3D mMove, mScale;
+   private Static1D mRadius;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   GlowRenderer(GLSurfaceView v)
+      {     
+      mView = v;
+
+      mRootW = LEAF_SIZE;
+      mRootH = LEAF_SIZE;
+      mLeaf  = new DistortedTexture(LEAF_SIZE,LEAF_SIZE);
+      mMove  = new Static3D(0,0,0);
+      mScale = new Static3D(1,1,1);
+      mRadius= new Static1D(25);
+
+      Static4D color = new Static4D(1.0f,1.0f,0.0f,0.5f); // half-transparent yellow
+
+      DistortedEffects effects = new DistortedEffects();
+      effects.apply(new MatrixEffectMove(mMove));
+      effects.apply(new MatrixEffectScale(mScale));
+      effects.apply(new PostprocessEffectGlow(mRadius,color));
+
+      mScreen = new DistortedScreen();
+      mScreen.attach(mLeaf, effects, new MeshFlat(1,1) );
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   int setGlow(int glow)
+     {
+     int radius = glow/2;
+     mRadius.set(radius);
+     return radius;
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   public void onDrawFrame(GL10 glUnused)
+     {
+     mScreen.render(System.currentTimeMillis());
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+   public void onSurfaceChanged(GL10 glUnused, int width, int height)
+     {
+     float qw = (float)width /mRootW;
+     float qh = (float)height/mRootH;
+     float factor = 0.5f* (qw<qh ? qw:qh);
+     int w = (int)(factor*mRootW);
+     int h = (int)(factor*mRootH);
+
+     mMove.set((width-w)/2 ,(height-h)/2, 0);
+     mScale.set( factor,factor,factor );
+     mScreen.resize(width, height);
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
+     {
+     InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
+     Bitmap leaf;
+      
+     try
+       {
+       leaf = BitmapFactory.decodeStream(is);
+       }
+     finally
+       {
+       try
+         {
+         is.close();
+         }
+       catch(IOException e) { }
+       }
+      
+     mLeaf.setTexture(leaf);
+
+     PostprocessEffectGlow.enable();
+
+     try
+       {
+       Distorted.onCreate(mView.getContext());
+       }
+     catch(Exception ex)
+       {
+       android.util.Log.e("Glow", ex.getMessage() );
+       }
+     }
+}
diff --git a/src/main/java/org/distorted/examples/glow/GlowSurfaceView.java b/src/main/java/org/distorted/examples/glow/GlowSurfaceView.java
new file mode 100644
index 0000000..7cb2e79
--- /dev/null
+++ b/src/main/java/org/distorted/examples/glow/GlowSurfaceView.java
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.glow;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ConfigurationInfo;
+import android.opengl.GLSurfaceView;
+import android.util.AttributeSet;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class GlowSurfaceView extends GLSurfaceView
+{
+  private GlowRenderer mRenderer;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public GlowSurfaceView(Context context, AttributeSet attrs)
+      {
+      super(context, attrs);
+
+      if(!isInEditMode())
+        {
+        mRenderer = new GlowRenderer(this);
+        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
+        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
+        setRenderer(mRenderer);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  GlowRenderer getRenderer()
+    {
+    return mRenderer;
+    }
+}
+
diff --git a/src/main/res/drawable-hdpi/icon_example_movingglow.png b/src/main/res/drawable-hdpi/icon_example_movingglow.png
new file mode 100644
index 0000000..3ff1318
Binary files /dev/null and b/src/main/res/drawable-hdpi/icon_example_movingglow.png differ
diff --git a/src/main/res/layout/glowlayout.xml b/src/main/res/layout/glowlayout.xml
new file mode 100644
index 0000000..a1e9e52
--- /dev/null
+++ b/src/main/res/layout/glowlayout.xml
@@ -0,0 +1,39 @@
+<?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.glow.GlowSurfaceView
+        android:id="@+id/glowSurfaceView"
+        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" >
+
+        <TextView
+                android:id="@+id/glowText"
+                android:layout_width="150dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="0.5"
+                android:gravity="center_vertical|center"
+                android:text="@string/glow"
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+
+        <SeekBar
+                android:id="@+id/glowSeek"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:paddingLeft="15dp"
+                android:paddingRight="10dp" />
+
+    </LinearLayout>
+
+</LinearLayout>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 0374ba6..c337e58 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -14,6 +14,7 @@
     <string name="contrast">Contrast</string>
     <string name="swirl">Swirl</string>
     <string name="blur">Blur</string>
+    <string name="glow">Glow</string>
 
     <string name="continu">Continue</string>
     <string name="rows">Rows</string>
@@ -84,6 +85,7 @@
     <string name="near_placeholder">Near: %1$.2f</string>
     <string name="wind_placeholder">Wind: %1$d</string>
     <string name="blur_placeholder">Blur: %1$d</string>
+    <string name="glow_placeholder">Glow: %1$d</string>
 
     <string name="example_monalisa">Mona Lisa</string>  
     <string name="example_monalisa_subtitle">The basics of Distortions.</string>
@@ -145,6 +147,8 @@
     <string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</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_glow">Glowing Leaf</string>
+    <string name="example_glow_subtitle">Leaf glowing with light.</string>
     <string name="example_moving_glow">Glow Effect</string>
     <string name="example_moving_glow_subtitle">See moving objects glowing with light.</string>
 
