Revision 11298b49
Added by Leszek Koltunski over 7 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 |
<activity android:name=".movingglow.MovingGlowActivity"/>
|
|
50 | 50 |
</application> |
51 | 51 |
</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 |
import org.distorted.examples.movingglow.MovingGlowActivity;
|
|
68 | 68 |
|
69 | 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
70 | 70 |
|
... | ... | |
360 | 360 |
{ |
361 | 361 |
final Map<String, Object> item = new HashMap<>(); |
362 | 362 |
item.put(ITEM_IMAGE, R.drawable.icon_example_glow); |
363 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_glow)); |
|
364 |
item.put(ITEM_SUBTITLE, getText(R.string.example_glow_subtitle)); |
|
363 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_moving_glow));
|
|
364 |
item.put(ITEM_SUBTITLE, getText(R.string.example_moving_glow_subtitle));
|
|
365 | 365 |
data.add(item); |
366 |
activityMapping.put(i++, GlowActivity.class); |
|
366 |
activityMapping.put(i++, MovingGlowActivity.class);
|
|
367 | 367 |
} |
368 | 368 |
|
369 | 369 |
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}); |
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.os.Bundle; |
|
24 |
import org.distorted.library.main.Distorted; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
public class GlowActivity extends Activity |
|
29 |
{ |
|
30 |
private GlowSurfaceView mView; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
@Override |
|
35 |
protected void onCreate(Bundle savedState) |
|
36 |
{ |
|
37 |
super.onCreate(savedState); |
|
38 |
mView = new GlowSurfaceView(this); |
|
39 |
setContentView(mView); |
|
40 |
} |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void onPause() |
|
46 |
{ |
|
47 |
mView.onPause(); |
|
48 |
Distorted.onPause(); |
|
49 |
super.onPause(); |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
@Override |
|
55 |
protected void onResume() |
|
56 |
{ |
|
57 |
super.onResume(); |
|
58 |
mView.onResume(); |
|
59 |
} |
|
60 |
|
|
61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
62 |
|
|
63 |
@Override |
|
64 |
protected void onDestroy() |
|
65 |
{ |
|
66 |
Distorted.onDestroy(); |
|
67 |
super.onDestroy(); |
|
68 |
} |
|
69 |
} |
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.EffectName; |
|
28 |
import org.distorted.library.effect.FragmentEffectChroma; |
|
29 |
import org.distorted.library.effect.MatrixEffectMove; |
|
30 |
import org.distorted.library.effect.MatrixEffectRotate; |
|
31 |
import org.distorted.library.effect.MatrixEffectScale; |
|
32 |
import org.distorted.library.effect.PostprocessEffectGlow; |
|
33 |
import org.distorted.library.main.Distorted; |
|
34 |
import org.distorted.library.main.DistortedEffects; |
|
35 |
import org.distorted.library.main.DistortedNode; |
|
36 |
import org.distorted.library.main.DistortedScreen; |
|
37 |
import org.distorted.library.main.DistortedTexture; |
|
38 |
import org.distorted.library.main.MeshFlat; |
|
39 |
import org.distorted.library.main.MeshObject; |
|
40 |
import org.distorted.library.message.EffectListener; |
|
41 |
import org.distorted.library.message.EffectMessage; |
|
42 |
import org.distorted.library.type.Dynamic1D; |
|
43 |
import org.distorted.library.type.Dynamic4D; |
|
44 |
import org.distorted.library.type.Static1D; |
|
45 |
import org.distorted.library.type.Static3D; |
|
46 |
import org.distorted.library.type.Static4D; |
|
47 |
|
|
48 |
import java.io.IOException; |
|
49 |
import java.io.InputStream; |
|
50 |
|
|
51 |
import javax.microedition.khronos.egl.EGLConfig; |
|
52 |
import javax.microedition.khronos.opengles.GL10; |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
|
|
56 |
class GlowRenderer implements GLSurfaceView.Renderer,EffectListener |
|
57 |
{ |
|
58 |
private static final int[] colors = new int[] {0,0,1, 0,0,0, 1,0,0, 1,1,0, 0,1,0, 1,1,1}; // blue, black, red, yellow, green, white |
|
59 |
private static final int LEAF_SIZE = 100; |
|
60 |
private static final int NUM_LEAVES= colors.length/3; |
|
61 |
|
|
62 |
private GLSurfaceView mView; |
|
63 |
private DistortedTexture mLeaf; |
|
64 |
private DistortedScreen mScreen; |
|
65 |
private DistortedEffects[] mLeafEffects = new DistortedEffects[NUM_LEAVES]; |
|
66 |
private PostprocessEffectGlow[] mGlow = new PostprocessEffectGlow[NUM_LEAVES]; |
|
67 |
private int mRootW, mRootH; |
|
68 |
private int mGlowing; |
|
69 |
private Static3D mMove, mScale; |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
GlowRenderer(GLSurfaceView v) |
|
74 |
{ |
|
75 |
mView = v; |
|
76 |
|
|
77 |
mRootW = 3*LEAF_SIZE; |
|
78 |
mRootH = 3*LEAF_SIZE; |
|
79 |
|
|
80 |
mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE); |
|
81 |
DistortedTexture surface = new DistortedTexture(mRootW,mRootH); |
|
82 |
MeshObject mesh = new MeshFlat(1,1); |
|
83 |
|
|
84 |
DistortedNode root = new DistortedNode(surface, new DistortedEffects(), mesh); |
|
85 |
|
|
86 |
Static3D moveVector = new Static3D(0,LEAF_SIZE,0); |
|
87 |
Static1D chromaLevel= new Static1D(0.5f); |
|
88 |
Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0); |
|
89 |
Static3D axis = new Static3D(0,0,1); |
|
90 |
|
|
91 |
MatrixEffectMove leafMove = new MatrixEffectMove(moveVector); |
|
92 |
|
|
93 |
for(int j=0; j<NUM_LEAVES; j++) |
|
94 |
{ |
|
95 |
mLeafEffects[j] = new DistortedEffects(); |
|
96 |
mLeafEffects[j].registerForMessages(this); |
|
97 |
mLeafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) ); |
|
98 |
mLeafEffects[j].apply(leafMove); |
|
99 |
mLeafEffects[j].apply( new FragmentEffectChroma(chromaLevel, new Static3D(colors[3*j],colors[3*j+1], colors[3*j+2])) ); |
|
100 |
DistortedNode node = new DistortedNode( mLeaf, mLeafEffects[j], mesh); |
|
101 |
root.attach(node); |
|
102 |
} |
|
103 |
|
|
104 |
mMove = new Static3D(0,0,0); |
|
105 |
mScale= new Static3D(1,1,1); |
|
106 |
|
|
107 |
Dynamic1D rot = new Dynamic1D(5000,0.0f); |
|
108 |
rot.setMode(Dynamic1D.MODE_JUMP); |
|
109 |
rot.add(new Static1D( 0)); |
|
110 |
rot.add(new Static1D(360)); |
|
111 |
|
|
112 |
DistortedEffects effects = root.getEffects(); |
|
113 |
effects.apply(new MatrixEffectMove(mMove)); |
|
114 |
effects.apply(new MatrixEffectScale(mScale)); |
|
115 |
effects.apply( new MatrixEffectRotate(rot, axis, center) ); |
|
116 |
|
|
117 |
Dynamic1D radiusDyn = new Dynamic1D(3000,1.0f); |
|
118 |
radiusDyn.add(new Static1D( 0)); |
|
119 |
radiusDyn.add(new Static1D(50)); |
|
120 |
|
|
121 |
for(int leaf=0; leaf<NUM_LEAVES; leaf++) |
|
122 |
{ |
|
123 |
Dynamic4D color = new Dynamic4D(5000,1.0f); |
|
124 |
Static4D startC = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 0); |
|
125 |
Static4D endC = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 1); |
|
126 |
color.add(startC); |
|
127 |
color.add(endC); |
|
128 |
|
|
129 |
mGlow[leaf] = new PostprocessEffectGlow(radiusDyn,color); |
|
130 |
} |
|
131 |
|
|
132 |
makeGlow(0); |
|
133 |
|
|
134 |
mScreen = new DistortedScreen(); |
|
135 |
mScreen.attach(root); |
|
136 |
} |
|
137 |
|
|
138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
139 |
|
|
140 |
private void makeGlow(int leaf) |
|
141 |
{ |
|
142 |
//android.util.Log.e("glow", "glowing: "+leaf); |
|
143 |
|
|
144 |
mGlowing = leaf; |
|
145 |
mLeafEffects[leaf].apply(mGlow[leaf]); |
|
146 |
} |
|
147 |
|
|
148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
149 |
// Glow finished. Make the next Leaf glow. |
|
150 |
|
|
151 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
|
152 |
{ |
|
153 |
switch(em) |
|
154 |
{ |
|
155 |
case EFFECT_FINISHED: //android.util.Log.e("glow", "effectMessage FINISHED"); |
|
156 |
int glowing = mGlowing+1; |
|
157 |
if( glowing>=NUM_LEAVES ) glowing = 0; |
|
158 |
makeGlow(glowing); |
|
159 |
break; |
|
160 |
default: //android.util.Log.e("glow", "effectMessage REMOVED"); |
|
161 |
break; |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
|
167 |
public void onDrawFrame(GL10 glUnused) |
|
168 |
{ |
|
169 |
mScreen.render(System.currentTimeMillis()); |
|
170 |
} |
|
171 |
|
|
172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
173 |
|
|
174 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
175 |
{ |
|
176 |
float qw = (float)width /mRootW; |
|
177 |
float qh = (float)height/mRootH; |
|
178 |
float factor = 0.6f* (qw<qh ? qw:qh); |
|
179 |
int w = (int)(factor*mRootW); |
|
180 |
int h = (int)(factor*mRootH); |
|
181 |
|
|
182 |
mMove.set((width-w)/2 ,(height-h)/2, 0); |
|
183 |
mScale.set( factor,factor,factor ); |
|
184 |
mScreen.resize(width, height); |
|
185 |
} |
|
186 |
|
|
187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
188 |
|
|
189 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
190 |
{ |
|
191 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf); |
|
192 |
Bitmap leaf; |
|
193 |
|
|
194 |
try |
|
195 |
{ |
|
196 |
leaf = BitmapFactory.decodeStream(is); |
|
197 |
} |
|
198 |
finally |
|
199 |
{ |
|
200 |
try |
|
201 |
{ |
|
202 |
is.close(); |
|
203 |
} |
|
204 |
catch(IOException e) { } |
|
205 |
} |
|
206 |
|
|
207 |
mLeaf.setTexture(leaf); |
|
208 |
|
|
209 |
FragmentEffectChroma.enable(); |
|
210 |
PostprocessEffectGlow.enable(); |
|
211 |
|
|
212 |
try |
|
213 |
{ |
|
214 |
Distorted.onCreate(mView.getContext()); |
|
215 |
} |
|
216 |
catch(Exception ex) |
|
217 |
{ |
|
218 |
android.util.Log.e("Glow", ex.getMessage() ); |
|
219 |
} |
|
220 |
} |
|
221 |
} |
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 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class GlowSurfaceView extends GLSurfaceView |
|
30 |
{ |
|
31 |
public GlowSurfaceView(Context context) |
|
32 |
{ |
|
33 |
super(context); |
|
34 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
35 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
36 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
37 |
setRenderer(new GlowRenderer(this)); |
|
38 |
} |
|
39 |
} |
|
40 |
|
src/main/java/org/distorted/examples/movingglow/MovingGlowActivity.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.movingglow; |
|
21 |
|
|
22 |
import android.app.Activity; |
|
23 |
import android.os.Bundle; |
|
24 |
import org.distorted.library.main.Distorted; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
public class MovingGlowActivity extends Activity |
|
29 |
{ |
|
30 |
private MovingGlowSurfaceView mView; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
@Override |
|
35 |
protected void onCreate(Bundle savedState) |
|
36 |
{ |
|
37 |
super.onCreate(savedState); |
|
38 |
mView = new MovingGlowSurfaceView(this); |
|
39 |
setContentView(mView); |
|
40 |
} |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void onPause() |
|
46 |
{ |
|
47 |
mView.onPause(); |
|
48 |
Distorted.onPause(); |
|
49 |
super.onPause(); |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
@Override |
|
55 |
protected void onResume() |
|
56 |
{ |
|
57 |
super.onResume(); |
|
58 |
mView.onResume(); |
|
59 |
} |
|
60 |
|
|
61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
62 |
|
|
63 |
@Override |
|
64 |
protected void onDestroy() |
|
65 |
{ |
|
66 |
Distorted.onDestroy(); |
|
67 |
super.onDestroy(); |
|
68 |
} |
|
69 |
} |
src/main/java/org/distorted/examples/movingglow/MovingGlowRenderer.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.movingglow; |
|
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.FragmentEffectChroma; |
|
28 |
import org.distorted.library.effect.MatrixEffectMove; |
|
29 |
import org.distorted.library.effect.MatrixEffectRotate; |
|
30 |
import org.distorted.library.effect.MatrixEffectScale; |
|
31 |
import org.distorted.library.effect.PostprocessEffectGlow; |
|
32 |
import org.distorted.library.main.Distorted; |
|
33 |
import org.distorted.library.main.DistortedEffects; |
|
34 |
import org.distorted.library.main.DistortedNode; |
|
35 |
import org.distorted.library.main.DistortedScreen; |
|
36 |
import org.distorted.library.main.DistortedTexture; |
|
37 |
import org.distorted.library.main.MeshFlat; |
|
38 |
import org.distorted.library.main.MeshObject; |
|
39 |
import org.distorted.library.message.EffectListener; |
|
40 |
import org.distorted.library.message.EffectMessage; |
|
41 |
import org.distorted.library.type.Dynamic1D; |
|
42 |
import org.distorted.library.type.Dynamic4D; |
|
43 |
import org.distorted.library.type.Static1D; |
|
44 |
import org.distorted.library.type.Static3D; |
|
45 |
import org.distorted.library.type.Static4D; |
|
46 |
|
|
47 |
import java.io.IOException; |
|
48 |
import java.io.InputStream; |
|
49 |
|
|
50 |
import javax.microedition.khronos.egl.EGLConfig; |
|
51 |
import javax.microedition.khronos.opengles.GL10; |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
class MovingGlowRenderer implements GLSurfaceView.Renderer,EffectListener |
|
56 |
{ |
|
57 |
private static final int[] colors = new int[] {0,0,1, 0,0,0, 1,0,0, 1,1,0, 0,1,0, 1,1,1}; // blue, black, red, yellow, green, white |
|
58 |
private static final int LEAF_SIZE = 100; |
|
59 |
private static final int NUM_LEAVES= colors.length/3; |
|
60 |
|
|
61 |
private GLSurfaceView mView; |
|
62 |
private DistortedTexture mLeaf; |
|
63 |
private DistortedScreen mScreen; |
|
64 |
private DistortedEffects[] mLeafEffects = new DistortedEffects[NUM_LEAVES]; |
|
65 |
private PostprocessEffectGlow[] mGlow = new PostprocessEffectGlow[NUM_LEAVES]; |
|
66 |
private int mRootW, mRootH; |
|
67 |
private int mGlowing; |
|
68 |
private Static3D mMove, mScale; |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
MovingGlowRenderer(GLSurfaceView v) |
|
73 |
{ |
|
74 |
mView = v; |
|
75 |
|
|
76 |
mRootW = 3*LEAF_SIZE; |
|
77 |
mRootH = 3*LEAF_SIZE; |
|
78 |
|
|
79 |
mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE); |
|
80 |
DistortedTexture surface = new DistortedTexture(mRootW,mRootH); |
|
81 |
MeshObject mesh = new MeshFlat(1,1); |
|
82 |
|
|
83 |
DistortedNode root = new DistortedNode(surface, new DistortedEffects(), mesh); |
|
84 |
|
|
85 |
Static3D moveVector = new Static3D(0,LEAF_SIZE,0); |
|
86 |
Static1D chromaLevel= new Static1D(0.5f); |
|
87 |
Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0); |
|
88 |
Static3D axis = new Static3D(0,0,1); |
|
89 |
|
|
90 |
MatrixEffectMove leafMove = new MatrixEffectMove(moveVector); |
|
91 |
|
|
92 |
for(int j=0; j<NUM_LEAVES; j++) |
|
93 |
{ |
|
94 |
mLeafEffects[j] = new DistortedEffects(); |
|
95 |
mLeafEffects[j].registerForMessages(this); |
|
96 |
mLeafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) ); |
|
97 |
mLeafEffects[j].apply(leafMove); |
|
98 |
mLeafEffects[j].apply( new FragmentEffectChroma(chromaLevel, new Static3D(colors[3*j],colors[3*j+1], colors[3*j+2])) ); |
|
99 |
DistortedNode node = new DistortedNode( mLeaf, mLeafEffects[j], mesh); |
|
100 |
root.attach(node); |
|
101 |
} |
|
102 |
|
|
103 |
mMove = new Static3D(0,0,0); |
|
104 |
mScale= new Static3D(1,1,1); |
|
105 |
|
|
106 |
Dynamic1D rot = new Dynamic1D(5000,0.0f); |
|
107 |
rot.setMode(Dynamic1D.MODE_JUMP); |
|
108 |
rot.add(new Static1D( 0)); |
|
109 |
rot.add(new Static1D(360)); |
|
110 |
|
|
111 |
DistortedEffects effects = root.getEffects(); |
|
112 |
effects.apply(new MatrixEffectMove(mMove)); |
|
113 |
effects.apply(new MatrixEffectScale(mScale)); |
|
114 |
effects.apply( new MatrixEffectRotate(rot, axis, center) ); |
|
115 |
|
|
116 |
Dynamic1D radiusDyn = new Dynamic1D(3000,1.0f); |
|
117 |
radiusDyn.add(new Static1D( 0)); |
|
118 |
radiusDyn.add(new Static1D(50)); |
|
119 |
|
|
120 |
for(int leaf=0; leaf<NUM_LEAVES; leaf++) |
|
121 |
{ |
|
122 |
Dynamic4D color = new Dynamic4D(5000,1.0f); |
|
123 |
Static4D startC = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 0); |
|
124 |
Static4D endC = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 1); |
|
125 |
color.add(startC); |
|
126 |
color.add(endC); |
|
127 |
|
|
128 |
mGlow[leaf] = new PostprocessEffectGlow(radiusDyn,color); |
|
129 |
} |
|
130 |
|
|
131 |
makeGlow(0); |
|
132 |
|
|
133 |
mScreen = new DistortedScreen(); |
|
134 |
mScreen.attach(root); |
|
135 |
} |
|
136 |
|
|
137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
138 |
|
|
139 |
private void makeGlow(int leaf) |
|
140 |
{ |
|
141 |
//android.util.Log.e("glow", "glowing: "+leaf); |
|
142 |
|
|
143 |
mGlowing = leaf; |
|
144 |
mLeafEffects[leaf].apply(mGlow[leaf]); |
|
145 |
} |
|
146 |
|
|
147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
148 |
// Glow finished. Make the next Leaf glow. |
|
149 |
|
|
150 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
|
151 |
{ |
|
152 |
switch(em) |
|
153 |
{ |
|
154 |
case EFFECT_FINISHED: //android.util.Log.e("glow", "effectMessage FINISHED"); |
|
155 |
int glowing = mGlowing+1; |
|
156 |
if( glowing>=NUM_LEAVES ) glowing = 0; |
|
157 |
makeGlow(glowing); |
|
158 |
break; |
|
159 |
default: //android.util.Log.e("glow", "effectMessage REMOVED"); |
|
160 |
break; |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
165 |
|
|
166 |
public void onDrawFrame(GL10 glUnused) |
|
167 |
{ |
|
168 |
mScreen.render(System.currentTimeMillis()); |
|
169 |
} |
|
170 |
|
|
171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
|
|
173 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
174 |
{ |
|
175 |
float qw = (float)width /mRootW; |
|
176 |
float qh = (float)height/mRootH; |
|
177 |
float factor = 0.6f* (qw<qh ? qw:qh); |
|
178 |
int w = (int)(factor*mRootW); |
|
179 |
int h = (int)(factor*mRootH); |
|
180 |
|
|
181 |
mMove.set((width-w)/2 ,(height-h)/2, 0); |
|
182 |
mScale.set( factor,factor,factor ); |
|
183 |
mScreen.resize(width, height); |
|
184 |
} |
|
185 |
|
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
|
|
188 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
189 |
{ |
|
190 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf); |
|
191 |
Bitmap leaf; |
|
192 |
|
|
193 |
try |
|
194 |
{ |
|
195 |
leaf = BitmapFactory.decodeStream(is); |
|
196 |
} |
|
197 |
finally |
|
198 |
{ |
|
199 |
try |
|
200 |
{ |
|
201 |
is.close(); |
|
202 |
} |
|
203 |
catch(IOException e) { } |
|
204 |
} |
|
205 |
|
|
206 |
mLeaf.setTexture(leaf); |
|
207 |
|
|
208 |
FragmentEffectChroma.enable(); |
|
209 |
PostprocessEffectGlow.enable(); |
|
210 |
|
|
211 |
try |
|
212 |
{ |
|
213 |
Distorted.onCreate(mView.getContext()); |
|
214 |
} |
|
215 |
catch(Exception ex) |
|
216 |
{ |
|
217 |
android.util.Log.e("MovingGlow", ex.getMessage() ); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
src/main/java/org/distorted/examples/movingglow/MovingGlowSurfaceView.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.movingglow; |
|
21 |
|
|
22 |
import android.app.ActivityManager; |
|
23 |
import android.content.Context; |
|
24 |
import android.content.pm.ConfigurationInfo; |
|
25 |
import android.opengl.GLSurfaceView; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class MovingGlowSurfaceView extends GLSurfaceView |
|
30 |
{ |
|
31 |
public MovingGlowSurfaceView(Context context) |
|
32 |
{ |
|
33 |
super(context); |
|
34 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
35 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
36 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
37 |
setRenderer(new MovingGlowRenderer(this)); |
|
38 |
} |
|
39 |
} |
|
40 |
|
src/main/res/values/strings.xml | ||
---|---|---|
145 | 145 |
<string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</string> |
146 | 146 |
<string name="example_stencil">Stencil Buffer</string> |
147 | 147 |
<string name="example_stencil_subtitle">Implement the classic stencil example from https://open.gl/depthstencils</string> |
148 |
<string name="example_glow">Glow Effect</string> |
|
149 |
<string name="example_glow_subtitle">See objects glowing with light.</string>
|
|
148 |
<string name="example_moving_glow">Glow Effect</string>
|
|
149 |
<string name="example_moving_glow_subtitle">See moving objects glowing with light.</string>
|
|
150 | 150 |
|
151 | 151 |
<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> |
152 | 152 |
<string name="example_rotate_toast">Rotate the scene by swiping the screen</string> |
Also available in: Unified diff
Rename the last 'Glow' app.