Revision 36532c7f
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/examples/flatblur/FlatBlurActivity.java | ||
---|---|---|
23 | 23 |
import android.opengl.GLSurfaceView; |
24 | 24 |
import android.os.Bundle; |
25 | 25 |
import android.view.View; |
26 |
import android.widget.CheckBox; |
|
27 |
import android.widget.SeekBar; |
|
28 | 26 |
|
29 | 27 |
import org.distorted.examples.R; |
30 | 28 |
import org.distorted.library.main.DistortedLibrary; |
31 | 29 |
|
32 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 | 31 |
|
34 |
public class FlatBlurActivity extends Activity implements SeekBar.OnSeekBarChangeListener
|
|
32 |
public class FlatBlurActivity extends Activity |
|
35 | 33 |
{ |
36 | 34 |
@Override |
37 | 35 |
protected void onCreate(Bundle savedState) |
... | ... | |
39 | 37 |
super.onCreate(savedState); |
40 | 38 |
DistortedLibrary.onCreate(); |
41 | 39 |
setContentView(R.layout.flatblurlayout); |
42 |
|
|
43 |
SeekBar barSize = findViewById(R.id.flatblurBlurStrength); |
|
44 |
barSize.setOnSeekBarChangeListener(this); |
|
45 |
barSize.setProgress(0); |
|
46 | 40 |
} |
47 | 41 |
|
48 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
77 | 71 |
|
78 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
79 | 73 |
|
80 |
public void enableBlur(View view)
|
|
74 |
public void button1(View view)
|
|
81 | 75 |
{ |
82 |
CheckBox box = (CheckBox)view; |
|
83 |
boolean checked = box.isChecked(); |
|
84 |
|
|
85 | 76 |
FlatBlurSurfaceView v = findViewById(R.id.flatblurSurfaceView); |
86 | 77 |
FlatBlurRenderer renderer = v.getRenderer(); |
87 |
renderer.enableBlur(!checked);
|
|
78 |
renderer.button1();
|
|
88 | 79 |
} |
89 | 80 |
|
90 | 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
91 | 82 |
|
92 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
93 |
{ |
|
94 |
FlatBlurSurfaceView v = findViewById(R.id.flatblurSurfaceView); |
|
95 |
FlatBlurRenderer renderer = v.getRenderer(); |
|
96 |
renderer.setBlurStrength(progress); |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
|
105 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
83 |
public void button2(View view) |
|
84 |
{ |
|
85 |
FlatBlurSurfaceView v = findViewById(R.id.flatblurSurfaceView); |
|
86 |
FlatBlurRenderer renderer = v.getRenderer(); |
|
87 |
renderer.button2(); |
|
88 |
} |
|
106 | 89 |
} |
src/main/java/org/distorted/examples/flatblur/FlatBlurRenderer.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.opengl.GLSurfaceView; |
23 | 23 |
|
24 |
import org.distorted.library.effect.EffectQuality; |
|
25 |
import org.distorted.library.effect.MatrixEffectMove; |
|
26 |
import org.distorted.library.effect.MatrixEffectScale; |
|
27 |
import org.distorted.library.effect.PostprocessEffectBlur; |
|
28 |
import org.distorted.library.main.DistortedEffects; |
|
29 | 24 |
import org.distorted.library.main.DistortedLibrary; |
30 |
import org.distorted.library.main.DistortedNode; |
|
31 | 25 |
import org.distorted.library.main.DistortedScreen; |
32 |
import org.distorted.library.main.DistortedTexture; |
|
33 |
import org.distorted.library.mesh.MeshQuad; |
|
34 |
import org.distorted.library.type.Static2D; |
|
35 |
import org.distorted.library.type.Static3D; |
|
36 | 26 |
|
37 | 27 |
import javax.microedition.khronos.egl.EGLConfig; |
38 | 28 |
import javax.microedition.khronos.opengles.GL10; |
... | ... | |
41 | 31 |
|
42 | 32 |
class FlatBlurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
43 | 33 |
{ |
44 |
private static final int HALO = 15; |
|
45 |
|
|
46 | 34 |
private final GLSurfaceView mView; |
47 | 35 |
private final DistortedScreen mScreen; |
48 |
private final PostprocessEffectBlur mBlur; |
|
49 |
private final DistortedNode mRedNode; |
|
50 |
private final Static2D mBlurStrength; |
|
51 | 36 |
|
52 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
53 | 38 |
|
... | ... | |
55 | 40 |
{ |
56 | 41 |
mView = v; |
57 | 42 |
mScreen = new DistortedScreen(); |
58 |
|
|
59 |
int x = 50; |
|
60 |
int scale = 200; |
|
61 |
mRedNode = createNode(-x,0,1,scale,0xffff0000); |
|
62 |
DistortedNode whiteNode = createNode(x,0,1,scale,0xffffffff); |
|
63 |
|
|
64 |
mScreen.attach(mRedNode); |
|
65 |
mScreen.attach(whiteNode); |
|
66 |
|
|
67 |
mBlurStrength = new Static2D(HALO,0); |
|
68 |
mBlur = new PostprocessEffectBlur(mBlurStrength); |
|
69 |
mBlur.setQuality(EffectQuality.MEDIUM); |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
private DistortedNode createNode(int x, int y, int z, int scale, int color) |
|
75 |
{ |
|
76 |
DistortedTexture texture = new DistortedTexture(); |
|
77 |
texture.setColorARGB(color); |
|
78 |
MeshQuad mesh = new MeshQuad(); |
|
79 |
DistortedEffects effects = new DistortedEffects(); |
|
80 |
|
|
81 |
Static3D move = new Static3D(x,y,z); |
|
82 |
|
|
83 |
MatrixEffectMove mainMove = new MatrixEffectMove(move); |
|
84 |
MatrixEffectScale mainScale= new MatrixEffectScale(scale); |
|
85 |
|
|
86 |
effects.apply(mainScale); |
|
87 |
effects.apply(mainMove); |
|
88 |
|
|
89 |
return new DistortedNode(texture,effects,mesh); |
|
90 | 43 |
} |
91 | 44 |
|
92 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
107 | 60 |
|
108 | 61 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
109 | 62 |
{ |
110 |
PostprocessEffectBlur.enable();
|
|
63 |
OverlayStars.enableEffects();
|
|
111 | 64 |
DistortedLibrary.onSurfaceCreated( mView.getContext(), this); |
112 | 65 |
} |
113 | 66 |
|
... | ... | |
115 | 68 |
|
116 | 69 |
public void distortedException(Exception ex) |
117 | 70 |
{ |
118 |
android.util.Log.e("SetTexture", ex.getMessage() );
|
|
71 |
android.util.Log.e("FlatBlur", ex.getMessage() );
|
|
119 | 72 |
} |
120 | 73 |
|
121 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
122 | 75 |
|
123 |
public void enableBlur(boolean enable)
|
|
76 |
public void button1()
|
|
124 | 77 |
{ |
125 |
DistortedEffects effects = mRedNode.getEffects(); |
|
126 |
long id = mBlur.getID(); |
|
127 |
|
|
128 |
if( enable ) effects.abortById(id); |
|
129 |
else effects.apply(mBlur); |
|
78 |
OverlayStars stars = new OverlayStars(); |
|
79 |
stars.startOverlay(mScreen); |
|
130 | 80 |
} |
131 | 81 |
|
132 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
133 | 83 |
|
134 |
public void setBlurStrength(int strength)
|
|
84 |
public void button2()
|
|
135 | 85 |
{ |
136 |
mBlurStrength.set(HALO,strength*0.5f); |
|
86 |
|
|
137 | 87 |
} |
138 | 88 |
} |
src/main/java/org/distorted/examples/flatblur/FlatBlurSurfaceView.java | ||
---|---|---|
47 | 47 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
48 | 48 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
49 | 49 |
setRenderer(mRenderer); |
50 |
Toast.makeText(context, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show(); |
|
51 | 50 |
} |
52 | 51 |
} |
53 | 52 |
|
src/main/java/org/distorted/examples/flatblur/OverlayStars.java | ||
---|---|---|
1 |
package org.distorted.examples.flatblur; |
|
2 |
|
|
3 |
import org.distorted.library.effect.EffectQuality; |
|
4 |
import org.distorted.library.effect.PostprocessEffectGlow; |
|
5 |
import org.distorted.library.effect.VertexEffectMove; |
|
6 |
import org.distorted.library.effect.VertexEffectScale; |
|
7 |
import org.distorted.library.main.DistortedEffects; |
|
8 |
import org.distorted.library.main.DistortedNode; |
|
9 |
import org.distorted.library.main.DistortedScreen; |
|
10 |
import org.distorted.library.main.DistortedTexture; |
|
11 |
import org.distorted.library.main.InternalOutputSurface; |
|
12 |
import org.distorted.library.mesh.MeshJoined; |
|
13 |
import org.distorted.library.mesh.MeshQuad; |
|
14 |
import org.distorted.library.message.EffectListener; |
|
15 |
import org.distorted.library.type.Dynamic; |
|
16 |
import org.distorted.library.type.Dynamic2D; |
|
17 |
import org.distorted.library.type.Dynamic3D; |
|
18 |
import org.distorted.library.type.Dynamic4D; |
|
19 |
import org.distorted.library.type.Static2D; |
|
20 |
import org.distorted.library.type.Static3D; |
|
21 |
import org.distorted.library.type.Static4D; |
|
22 |
|
|
23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
24 |
|
|
25 |
public class OverlayStars implements EffectListener |
|
26 |
{ |
|
27 |
private static final int DUR_MOV = 4000; |
|
28 |
private static final int DUR_GLO = 2000; |
|
29 |
|
|
30 |
private static final int[] colors = new int[] {0,0,1, 1,0,1, 1,0,0, 1,1,0, 0,1,0, 1,1,1}; // blue, pink, red, yellow, green, white |
|
31 |
private static final int INDEX = 5; |
|
32 |
|
|
33 |
private DistortedNode mNode; |
|
34 |
private DistortedScreen mScreen; |
|
35 |
|
|
36 |
private float mWidth; |
|
37 |
private long mMoveID, mGlowID; |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
private Dynamic3D createRandomMove() |
|
42 |
{ |
|
43 |
Dynamic3D move = new Dynamic3D(); |
|
44 |
move.setMode(Dynamic.MODE_PATH); |
|
45 |
move.setDuration(DUR_MOV); |
|
46 |
move.setCount(0.5f); |
|
47 |
|
|
48 |
Static3D pointS = new Static3D(0,-500,0); |
|
49 |
Static3D pointE = new Static3D(0,0,0); |
|
50 |
|
|
51 |
move.add(pointS); |
|
52 |
move.add(pointE); |
|
53 |
|
|
54 |
return move; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
private DistortedNode createNode() |
|
60 |
{ |
|
61 |
DistortedTexture texture = new DistortedTexture(); |
|
62 |
texture.setColorARGB(0xffff0000); |
|
63 |
|
|
64 |
MeshQuad[] mesh = new MeshQuad[2]; |
|
65 |
mesh[0] = new MeshQuad(); |
|
66 |
mesh[1] = new MeshQuad(); |
|
67 |
mesh[0].setEffectAssociation(0,1,0); |
|
68 |
mesh[1].setEffectAssociation(0,2,1); |
|
69 |
|
|
70 |
MeshJoined wholeMesh = new MeshJoined(mesh); |
|
71 |
|
|
72 |
DistortedEffects effects = new DistortedEffects(); |
|
73 |
|
|
74 |
float scaleM = mWidth*0.40f; |
|
75 |
float scaleP = mWidth*0.15f; |
|
76 |
Static3D moveM= new Static3D(0,0,1); |
|
77 |
|
|
78 |
VertexEffectMove mainMove = new VertexEffectMove(moveM); |
|
79 |
VertexEffectScale mainScale = new VertexEffectScale(scaleM); |
|
80 |
mainMove.setMeshAssociation(2,-1); |
|
81 |
mainScale.setMeshAssociation(2,-1); |
|
82 |
|
|
83 |
VertexEffectScale scaleE = new VertexEffectScale(scaleP); |
|
84 |
scaleE.setMeshAssociation(1,-1); |
|
85 |
effects.apply(scaleE); |
|
86 |
|
|
87 |
Dynamic3D moveP = createRandomMove(); |
|
88 |
VertexEffectMove moveE= new VertexEffectMove(moveP); |
|
89 |
moveE.setMeshAssociation(0,0); |
|
90 |
effects.apply(moveE); |
|
91 |
|
|
92 |
mMoveID = moveE.getID(); |
|
93 |
moveE.notifyWhenFinished(this); |
|
94 |
|
|
95 |
effects.apply(mainMove); |
|
96 |
effects.apply(mainScale); |
|
97 |
|
|
98 |
return new DistortedNode(texture,effects,wholeMesh); |
|
99 |
} |
|
100 |
|
|
101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
102 |
|
|
103 |
public void startOverlay(DistortedScreen screen) |
|
104 |
{ |
|
105 |
mScreen = screen; |
|
106 |
mWidth = mScreen.getWidth(); |
|
107 |
|
|
108 |
mNode = createNode(); |
|
109 |
mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL); |
|
110 |
mScreen.attach(mNode); |
|
111 |
} |
|
112 |
|
|
113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
114 |
|
|
115 |
public void effectFinished(long id) |
|
116 |
{ |
|
117 |
if( id==mMoveID ) |
|
118 |
{ |
|
119 |
Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,1.0f); |
|
120 |
haloRadius.add(new Static2D( 0, 0)); |
|
121 |
haloRadius.add(new Static2D(15,50)); |
|
122 |
haloRadius.add(new Static2D( 0, 0)); |
|
123 |
|
|
124 |
Dynamic4D color= new Dynamic4D(DUR_GLO,1.0f); |
|
125 |
Static4D P1 = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.0f); |
|
126 |
Static4D P2 = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.5f); |
|
127 |
color.add(P1); |
|
128 |
color.add(P2); |
|
129 |
color.add(P1); |
|
130 |
|
|
131 |
PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color); |
|
132 |
glow.setQuality(EffectQuality.MEDIUM); |
|
133 |
mGlowID = glow.getID(); |
|
134 |
glow.notifyWhenFinished(this); |
|
135 |
DistortedEffects effects = mNode.getEffects(); |
|
136 |
effects.apply(glow); |
|
137 |
} |
|
138 |
if( id==mGlowID ) |
|
139 |
{ |
|
140 |
mScreen.detach(mNode); |
|
141 |
mNode.markForDeletion(); |
|
142 |
mNode=null; |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
147 |
|
|
148 |
@SuppressWarnings("unused") |
|
149 |
public static void enableEffects() |
|
150 |
{ |
|
151 |
VertexEffectMove.enable(); |
|
152 |
VertexEffectScale.enable(); |
|
153 |
PostprocessEffectGlow.enable(); |
|
154 |
} |
|
155 |
} |
src/main/res/layout/flatblurlayout.xml | ||
---|---|---|
16 | 16 |
android:layout_height="wrap_content" |
17 | 17 |
android:gravity="center"> |
18 | 18 |
|
19 |
<CheckBox
|
|
20 |
android:id="@+id/flatblurEnableBlur"
|
|
19 |
<Button
|
|
20 |
android:id="@+id/flatblurButton1"
|
|
21 | 21 |
android:layout_width="0dp" |
22 | 22 |
android:layout_height="match_parent" |
23 | 23 |
android:layout_weight="1" |
24 |
android:onClick="enableBlur"
|
|
24 |
android:onClick="button1"
|
|
25 | 25 |
android:checked="false"/> |
26 |
|
|
27 |
<SeekBar |
|
28 |
android:id="@+id/flatblurBlurStrength" |
|
26 |
<Button |
|
27 |
android:id="@+id/flatblurButton2" |
|
29 | 28 |
android:layout_width="0dp" |
30 | 29 |
android:layout_height="match_parent" |
31 |
android:layout_weight="2"
|
|
32 |
android:layout_gravity="center_vertical"
|
|
33 |
android:layout_margin="5dp"/>
|
|
30 |
android:layout_weight="1"
|
|
31 |
android:onClick="button2"
|
|
32 |
android:checked="false"/>
|
|
34 | 33 |
|
35 | 34 |
</LinearLayout> |
36 | 35 |
|
Also available in: Unified diff
This app reproduces an issue with glow being improperly displayed on my physical LG phone.