Revision cb9d104d
Added by Leszek Koltunski over 8 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 46 | 46 |
<activity android:name=".blur.BlurActivity"/> |
| 47 | 47 |
<activity android:name=".multiblur.MultiblurActivity"/> |
| 48 | 48 |
<activity android:name=".stencil.StencilActivity"/> |
| 49 |
<activity android:name=".glow.GlowActivity"/> |
|
| 49 | 50 |
<activity android:name=".movingglow.MovingGlowActivity"/> |
| 50 | 51 |
</application> |
| 51 | 52 |
</manifest> |
| src/main/java/org/distorted/examples/TableOfContents.java | ||
|---|---|---|
| 64 | 64 |
import org.distorted.examples.blur.BlurActivity; |
| 65 | 65 |
import org.distorted.examples.multiblur.MultiblurActivity; |
| 66 | 66 |
import org.distorted.examples.stencil.StencilActivity; |
| 67 |
import org.distorted.examples.glow.GlowActivity; |
|
| 67 | 68 |
import org.distorted.examples.movingglow.MovingGlowActivity; |
| 68 | 69 |
|
| 69 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 357 | 358 |
activityMapping.put(i++, StencilActivity.class); |
| 358 | 359 |
} |
| 359 | 360 |
|
| 360 |
{
|
|
| 361 |
{
|
|
| 361 | 362 |
final Map<String, Object> item = new HashMap<>(); |
| 362 | 363 |
item.put(ITEM_IMAGE, R.drawable.icon_example_glow); |
| 364 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_glow)); |
|
| 365 |
item.put(ITEM_SUBTITLE, getText(R.string.example_glow_subtitle)); |
|
| 366 |
data.add(item); |
|
| 367 |
activityMapping.put(i++, GlowActivity.class); |
|
| 368 |
} |
|
| 369 |
|
|
| 370 |
{
|
|
| 371 |
final Map<String, Object> item = new HashMap<>(); |
|
| 372 |
item.put(ITEM_IMAGE, R.drawable.icon_example_movingglow); |
|
| 363 | 373 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_moving_glow)); |
| 364 | 374 |
item.put(ITEM_SUBTITLE, getText(R.string.example_moving_glow_subtitle)); |
| 365 | 375 |
data.add(item); |
| src/main/java/org/distorted/examples/blur/BlurActivity.java | ||
|---|---|---|
| 41 | 41 |
protected void onCreate(Bundle icicle) |
| 42 | 42 |
{
|
| 43 | 43 |
super.onCreate(icicle); |
| 44 |
|
|
| 45 | 44 |
setContentView(R.layout.blurlayout); |
| 46 |
|
|
| 47 | 45 |
textBlur = (TextView)findViewById(R.id.blurText); |
| 48 |
|
|
| 49 | 46 |
SeekBar bar = (SeekBar)findViewById(R.id.blurSeek); |
| 50 |
|
|
| 51 | 47 |
bar.setOnSeekBarChangeListener(this); |
| 52 | 48 |
bar.setProgress(50); |
| 53 | 49 |
} |
| ... | ... | |
| 69 | 65 |
protected void onResume() |
| 70 | 66 |
{
|
| 71 | 67 |
super.onResume(); |
| 72 |
|
|
| 73 | 68 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.blurSurfaceView); |
| 74 | 69 |
view.onResume(); |
| 75 | 70 |
} |
| src/main/java/org/distorted/examples/glow/GlowActivity.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.examples.glow; |
|
| 21 |
|
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.widget.SeekBar; |
|
| 26 |
import android.widget.TextView; |
|
| 27 |
|
|
| 28 |
import org.distorted.examples.R; |
|
| 29 |
import org.distorted.library.main.Distorted; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
public class GlowActivity extends Activity implements SeekBar.OnSeekBarChangeListener |
|
| 34 |
{
|
|
| 35 |
private TextView textGlow; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
@Override |
|
| 40 |
protected void onCreate(Bundle savedState) |
|
| 41 |
{
|
|
| 42 |
super.onCreate(savedState); |
|
| 43 |
setContentView(R.layout.glowlayout); |
|
| 44 |
textGlow = (TextView)findViewById(R.id.glowText); |
|
| 45 |
SeekBar bar = (SeekBar)findViewById(R.id.glowSeek); |
|
| 46 |
bar.setOnSeekBarChangeListener(this); |
|
| 47 |
bar.setProgress(50); |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
@Override |
|
| 53 |
protected void onPause() |
|
| 54 |
{
|
|
| 55 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.glowSurfaceView); |
|
| 56 |
view.onPause(); |
|
| 57 |
Distorted.onPause(); |
|
| 58 |
super.onPause(); |
|
| 59 |
} |
|
| 60 |
|
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
|
|
| 63 |
@Override |
|
| 64 |
protected void onResume() |
|
| 65 |
{
|
|
| 66 |
super.onResume(); |
|
| 67 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.glowSurfaceView); |
|
| 68 |
view.onResume(); |
|
| 69 |
} |
|
| 70 |
|
|
| 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 72 |
|
|
| 73 |
@Override |
|
| 74 |
protected void onDestroy() |
|
| 75 |
{
|
|
| 76 |
Distorted.onDestroy(); |
|
| 77 |
super.onDestroy(); |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
| 83 |
{
|
|
| 84 |
GlowSurfaceView view = (GlowSurfaceView) this.findViewById(R.id.glowSurfaceView); |
|
| 85 |
|
|
| 86 |
switch (bar.getId()) |
|
| 87 |
{
|
|
| 88 |
case R.id.glowSeek: int level = view.getRenderer().setGlow(progress); |
|
| 89 |
textGlow.setText(getString(R.string.glow_placeholder,level)); |
|
| 90 |
break; |
|
| 91 |
} |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
/////////////////////////////////////////////////////////////////// |
|
| 95 |
|
|
| 96 |
public void onStartTrackingTouch(SeekBar bar) { }
|
|
| 97 |
|
|
| 98 |
/////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
public void onStopTrackingTouch(SeekBar bar) { }
|
|
| 101 |
|
|
| 102 |
} |
|
| src/main/java/org/distorted/examples/glow/GlowRenderer.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.examples.glow; |
|
| 21 |
|
|
| 22 |
import android.graphics.Bitmap; |
|
| 23 |
import android.graphics.BitmapFactory; |
|
| 24 |
import android.opengl.GLSurfaceView; |
|
| 25 |
|
|
| 26 |
import org.distorted.examples.R; |
|
| 27 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 28 |
import org.distorted.library.effect.MatrixEffectScale; |
|
| 29 |
import org.distorted.library.effect.PostprocessEffectGlow; |
|
| 30 |
import org.distorted.library.main.Distorted; |
|
| 31 |
import org.distorted.library.main.DistortedEffects; |
|
| 32 |
import org.distorted.library.main.DistortedScreen; |
|
| 33 |
import org.distorted.library.main.DistortedTexture; |
|
| 34 |
import org.distorted.library.main.MeshFlat; |
|
| 35 |
import org.distorted.library.type.Static1D; |
|
| 36 |
import org.distorted.library.type.Static3D; |
|
| 37 |
import org.distorted.library.type.Static4D; |
|
| 38 |
|
|
| 39 |
import java.io.IOException; |
|
| 40 |
import java.io.InputStream; |
|
| 41 |
|
|
| 42 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 43 |
import javax.microedition.khronos.opengles.GL10; |
|
| 44 |
|
|
| 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 46 |
|
|
| 47 |
class GlowRenderer implements GLSurfaceView.Renderer |
|
| 48 |
{
|
|
| 49 |
private static final int LEAF_SIZE = 100; |
|
| 50 |
|
|
| 51 |
private GLSurfaceView mView; |
|
| 52 |
private DistortedTexture mLeaf; |
|
| 53 |
private DistortedScreen mScreen; |
|
| 54 |
private int mRootW, mRootH; |
|
| 55 |
private Static3D mMove, mScale; |
|
| 56 |
private Static1D mRadius; |
|
| 57 |
|
|
| 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
GlowRenderer(GLSurfaceView v) |
|
| 61 |
{
|
|
| 62 |
mView = v; |
|
| 63 |
|
|
| 64 |
mRootW = LEAF_SIZE; |
|
| 65 |
mRootH = LEAF_SIZE; |
|
| 66 |
mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE); |
|
| 67 |
mMove = new Static3D(0,0,0); |
|
| 68 |
mScale = new Static3D(1,1,1); |
|
| 69 |
mRadius= new Static1D(25); |
|
| 70 |
|
|
| 71 |
Static4D color = new Static4D(1.0f,1.0f,0.0f,0.5f); // half-transparent yellow |
|
| 72 |
|
|
| 73 |
DistortedEffects effects = new DistortedEffects(); |
|
| 74 |
effects.apply(new MatrixEffectMove(mMove)); |
|
| 75 |
effects.apply(new MatrixEffectScale(mScale)); |
|
| 76 |
effects.apply(new PostprocessEffectGlow(mRadius,color)); |
|
| 77 |
|
|
| 78 |
mScreen = new DistortedScreen(); |
|
| 79 |
mScreen.attach(mLeaf, effects, new MeshFlat(1,1) ); |
|
| 80 |
} |
|
| 81 |
|
|
| 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 83 |
|
|
| 84 |
int setGlow(int glow) |
|
| 85 |
{
|
|
| 86 |
int radius = glow/2; |
|
| 87 |
mRadius.set(radius); |
|
| 88 |
return radius; |
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
|
|
| 93 |
public void onDrawFrame(GL10 glUnused) |
|
| 94 |
{
|
|
| 95 |
mScreen.render(System.currentTimeMillis()); |
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 101 |
{
|
|
| 102 |
float qw = (float)width /mRootW; |
|
| 103 |
float qh = (float)height/mRootH; |
|
| 104 |
float factor = 0.5f* (qw<qh ? qw:qh); |
|
| 105 |
int w = (int)(factor*mRootW); |
|
| 106 |
int h = (int)(factor*mRootH); |
|
| 107 |
|
|
| 108 |
mMove.set((width-w)/2 ,(height-h)/2, 0); |
|
| 109 |
mScale.set( factor,factor,factor ); |
|
| 110 |
mScreen.resize(width, height); |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 114 |
|
|
| 115 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 116 |
{
|
|
| 117 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf); |
|
| 118 |
Bitmap leaf; |
|
| 119 |
|
|
| 120 |
try |
|
| 121 |
{
|
|
| 122 |
leaf = BitmapFactory.decodeStream(is); |
|
| 123 |
} |
|
| 124 |
finally |
|
| 125 |
{
|
|
| 126 |
try |
|
| 127 |
{
|
|
| 128 |
is.close(); |
|
| 129 |
} |
|
| 130 |
catch(IOException e) { }
|
|
| 131 |
} |
|
| 132 |
|
|
| 133 |
mLeaf.setTexture(leaf); |
|
| 134 |
|
|
| 135 |
PostprocessEffectGlow.enable(); |
|
| 136 |
|
|
| 137 |
try |
|
| 138 |
{
|
|
| 139 |
Distorted.onCreate(mView.getContext()); |
|
| 140 |
} |
|
| 141 |
catch(Exception ex) |
|
| 142 |
{
|
|
| 143 |
android.util.Log.e("Glow", ex.getMessage() );
|
|
| 144 |
} |
|
| 145 |
} |
|
| 146 |
} |
|
| src/main/java/org/distorted/examples/glow/GlowSurfaceView.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.examples.glow; |
|
| 21 |
|
|
| 22 |
import android.app.ActivityManager; |
|
| 23 |
import android.content.Context; |
|
| 24 |
import android.content.pm.ConfigurationInfo; |
|
| 25 |
import android.opengl.GLSurfaceView; |
|
| 26 |
import android.util.AttributeSet; |
|
| 27 |
|
|
| 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 29 |
|
|
| 30 |
class GlowSurfaceView extends GLSurfaceView |
|
| 31 |
{
|
|
| 32 |
private GlowRenderer mRenderer; |
|
| 33 |
|
|
| 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 35 |
|
|
| 36 |
public GlowSurfaceView(Context context, AttributeSet attrs) |
|
| 37 |
{
|
|
| 38 |
super(context, attrs); |
|
| 39 |
|
|
| 40 |
if(!isInEditMode()) |
|
| 41 |
{
|
|
| 42 |
mRenderer = new GlowRenderer(this); |
|
| 43 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 44 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 45 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
| 46 |
setRenderer(mRenderer); |
|
| 47 |
} |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
GlowRenderer getRenderer() |
|
| 53 |
{
|
|
| 54 |
return mRenderer; |
|
| 55 |
} |
|
| 56 |
} |
|
| 57 |
|
|
| src/main/res/layout/glowlayout.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:layout_width="fill_parent" |
|
| 4 |
android:layout_height="fill_parent" |
|
| 5 |
android:orientation="vertical" > |
|
| 6 |
|
|
| 7 |
<org.distorted.examples.glow.GlowSurfaceView |
|
| 8 |
android:id="@+id/glowSurfaceView" |
|
| 9 |
android:layout_width="fill_parent" |
|
| 10 |
android:layout_height="0dp" |
|
| 11 |
android:layout_weight="1" /> |
|
| 12 |
|
|
| 13 |
<LinearLayout |
|
| 14 |
android:id="@+id/linearLayout1" |
|
| 15 |
android:layout_width="fill_parent" |
|
| 16 |
android:layout_height="wrap_content" |
|
| 17 |
android:gravity="center|fill_horizontal" |
|
| 18 |
android:orientation="horizontal" > |
|
| 19 |
|
|
| 20 |
<TextView |
|
| 21 |
android:id="@+id/glowText" |
|
| 22 |
android:layout_width="150dp" |
|
| 23 |
android:layout_height="wrap_content" |
|
| 24 |
android:layout_weight="0.5" |
|
| 25 |
android:gravity="center_vertical|center" |
|
| 26 |
android:text="@string/glow" |
|
| 27 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
| 28 |
|
|
| 29 |
<SeekBar |
|
| 30 |
android:id="@+id/glowSeek" |
|
| 31 |
android:layout_width="fill_parent" |
|
| 32 |
android:layout_height="wrap_content" |
|
| 33 |
android:layout_weight="1" |
|
| 34 |
android:paddingLeft="15dp" |
|
| 35 |
android:paddingRight="10dp" /> |
|
| 36 |
|
|
| 37 |
</LinearLayout> |
|
| 38 |
|
|
| 39 |
</LinearLayout> |
|
| src/main/res/values/strings.xml | ||
|---|---|---|
| 14 | 14 |
<string name="contrast">Contrast</string> |
| 15 | 15 |
<string name="swirl">Swirl</string> |
| 16 | 16 |
<string name="blur">Blur</string> |
| 17 |
<string name="glow">Glow</string> |
|
| 17 | 18 |
|
| 18 | 19 |
<string name="continu">Continue</string> |
| 19 | 20 |
<string name="rows">Rows</string> |
| ... | ... | |
| 84 | 85 |
<string name="near_placeholder">Near: %1$.2f</string> |
| 85 | 86 |
<string name="wind_placeholder">Wind: %1$d</string> |
| 86 | 87 |
<string name="blur_placeholder">Blur: %1$d</string> |
| 88 |
<string name="glow_placeholder">Glow: %1$d</string> |
|
| 87 | 89 |
|
| 88 | 90 |
<string name="example_monalisa">Mona Lisa</string> |
| 89 | 91 |
<string name="example_monalisa_subtitle">The basics of Distortions.</string> |
| ... | ... | |
| 145 | 147 |
<string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</string> |
| 146 | 148 |
<string name="example_stencil">Stencil Buffer</string> |
| 147 | 149 |
<string name="example_stencil_subtitle">Implement the classic stencil example from https://open.gl/depthstencils</string> |
| 150 |
<string name="example_glow">Glowing Leaf</string> |
|
| 151 |
<string name="example_glow_subtitle">Leaf glowing with light.</string> |
|
| 148 | 152 |
<string name="example_moving_glow">Glow Effect</string> |
| 149 | 153 |
<string name="example_moving_glow_subtitle">See moving objects glowing with light.</string> |
| 150 | 154 |
|
Also available in: Unified diff
New 'Glow' app.