Revision 0e65f4da
Added by Leszek Koltunski about 2 years ago
src/main/AndroidManifest.xml | ||
---|---|---|
61 | 61 |
<activity android:name=".deferredjob.DeferredJobActivity"/> |
62 | 62 |
<activity android:name=".singlemesh.SingleMeshActivity"/> |
63 | 63 |
<activity android:name=".meshfile.MeshFileActivity"/> |
64 |
<activity android:name=".flatblur.FlatBlurActivity"/> |
|
64 | 65 |
</application> |
65 | 66 |
</manifest> |
src/main/java/org/distorted/examples/TableOfContents.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
import org.distorted.examples.deferredjob.DeferredJobActivity; |
38 | 38 |
import org.distorted.examples.monalisa.MonaLisaActivity; |
39 |
import org.distorted.examples.flatblur.FlatBlurActivity; |
|
39 | 40 |
import org.distorted.examples.sink.SinkActivity; |
40 | 41 |
import org.distorted.examples.projection.ProjectionActivity; |
41 | 42 |
import org.distorted.examples.deform.DeformActivity; |
... | ... | |
86 | 87 |
|
87 | 88 |
private enum Application |
88 | 89 |
{ |
89 |
MESHFILE (R.drawable.icon_example_meshfile , R.string.example_meshfile , R.string.example_meshfile_subtitle , MeshFileActivity.class), |
|
90 |
|
|
91 |
|
|
92 | 90 |
MONALISA (R.drawable.icon_example_monalisa , R.string.example_monalisa , R.string.example_monalisa_subtitle , MonaLisaActivity.class), |
93 | 91 |
SINK (R.drawable.icon_example_sink , R.string.example_sink , R.string.example_sink_subtitle , SinkActivity.class), |
94 | 92 |
BEAN (R.drawable.icon_example_bean , R.string.example_bean , R.string.example_bean_subtitle , BeanActivity.class), |
... | ... | |
129 | 127 |
PREDEFORM (R.drawable.icon_example_predeform , R.string.example_predeform , R.string.example_predeform_subtitle , PredeformActivity.class), |
130 | 128 |
DEFERREDJOB (R.drawable.icon_example_deferredjob , R.string.example_deferredjob , R.string.example_deferredjob_subtitle , DeferredJobActivity.class), |
131 | 129 |
SINGLEMESH (R.drawable.icon_example_singlemesh , R.string.example_singlemesh , R.string.example_singlemesh_subtitle , SingleMeshActivity.class), |
130 |
MESHFILE (R.drawable.icon_example_meshfile , R.string.example_meshfile , R.string.example_meshfile_subtitle , MeshFileActivity.class), |
|
131 |
FLATBLUR (R.drawable.icon_example_flatblur , R.string.example_flatblur , R.string.example_flatblur_subtitle , FlatBlurActivity.class ), |
|
132 |
|
|
132 | 133 |
; |
133 | 134 |
|
134 | 135 |
final int icon, title, subtitle; |
src/main/java/org/distorted/examples/flatblur/FlatBlurActivity.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.flatblur; |
|
21 |
|
|
22 |
import android.app.Activity; |
|
23 |
import android.opengl.GLSurfaceView; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.view.View; |
|
26 |
import android.widget.CheckBox; |
|
27 |
import android.widget.SeekBar; |
|
28 |
|
|
29 |
import org.distorted.examples.R; |
|
30 |
import org.distorted.library.main.DistortedLibrary; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public class FlatBlurActivity extends Activity implements SeekBar.OnSeekBarChangeListener |
|
35 |
{ |
|
36 |
@Override |
|
37 |
protected void onCreate(Bundle savedState) |
|
38 |
{ |
|
39 |
super.onCreate(savedState); |
|
40 |
DistortedLibrary.onCreate(); |
|
41 |
setContentView(R.layout.flatblurlayout); |
|
42 |
|
|
43 |
SeekBar barSize = findViewById(R.id.flatblurBlurStrength); |
|
44 |
barSize.setOnSeekBarChangeListener(this); |
|
45 |
barSize.setProgress(0); |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
@Override |
|
51 |
protected void onPause() |
|
52 |
{ |
|
53 |
super.onPause(); |
|
54 |
GLSurfaceView view = findViewById(R.id.flatblurSurfaceView); |
|
55 |
view.onPause(); |
|
56 |
DistortedLibrary.onPause(); |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
|
61 |
@Override |
|
62 |
protected void onResume() |
|
63 |
{ |
|
64 |
super.onResume(); |
|
65 |
GLSurfaceView view = findViewById(R.id.flatblurSurfaceView); |
|
66 |
view.onResume(); |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
@Override |
|
72 |
protected void onDestroy() |
|
73 |
{ |
|
74 |
DistortedLibrary.onDestroy(); |
|
75 |
super.onDestroy(); |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
public void enableBlur(View view) |
|
81 |
{ |
|
82 |
CheckBox box = (CheckBox)view; |
|
83 |
boolean checked = box.isChecked(); |
|
84 |
|
|
85 |
FlatBlurSurfaceView v = findViewById(R.id.flatblurSurfaceView); |
|
86 |
FlatBlurRenderer renderer = v.getRenderer(); |
|
87 |
renderer.enableBlur(!checked); |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
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) { } |
|
106 |
} |
src/main/java/org/distorted/examples/flatblur/FlatBlurRenderer.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.flatblur; |
|
21 |
|
|
22 |
import android.opengl.GLSurfaceView; |
|
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 |
import org.distorted.library.main.DistortedLibrary; |
|
30 |
import org.distorted.library.main.DistortedNode; |
|
31 |
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 |
|
|
37 |
import javax.microedition.khronos.egl.EGLConfig; |
|
38 |
import javax.microedition.khronos.opengles.GL10; |
|
39 |
|
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
class FlatBlurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
|
43 |
{ |
|
44 |
private static final int HALO = 15; |
|
45 |
|
|
46 |
private final GLSurfaceView mView; |
|
47 |
private final DistortedScreen mScreen; |
|
48 |
private final PostprocessEffectBlur mBlur; |
|
49 |
private final DistortedNode mRedNode; |
|
50 |
private final Static2D mBlurStrength; |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
FlatBlurRenderer(GLSurfaceView v) |
|
55 |
{ |
|
56 |
mView = v; |
|
57 |
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 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public void onDrawFrame(GL10 glUnused) |
|
95 |
{ |
|
96 |
mScreen.render(System.currentTimeMillis()); |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
102 |
{ |
|
103 |
mScreen.resize(width,height); |
|
104 |
} |
|
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
109 |
{ |
|
110 |
PostprocessEffectBlur.enable(); |
|
111 |
DistortedLibrary.onSurfaceCreated( mView.getContext(), this); |
|
112 |
} |
|
113 |
|
|
114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
115 |
|
|
116 |
public void distortedException(Exception ex) |
|
117 |
{ |
|
118 |
android.util.Log.e("SetTexture", ex.getMessage() ); |
|
119 |
} |
|
120 |
|
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
123 |
public void enableBlur(boolean enable) |
|
124 |
{ |
|
125 |
DistortedEffects effects = mRedNode.getEffects(); |
|
126 |
long id = mBlur.getID(); |
|
127 |
|
|
128 |
if( enable ) effects.abortById(id); |
|
129 |
else effects.apply(mBlur); |
|
130 |
} |
|
131 |
|
|
132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
|
134 |
public void setBlurStrength(int strength) |
|
135 |
{ |
|
136 |
mBlurStrength.set(HALO,strength*0.5f); |
|
137 |
} |
|
138 |
} |
src/main/java/org/distorted/examples/flatblur/FlatBlurSurfaceView.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.flatblur; |
|
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 |
import android.widget.Toast; |
|
28 |
|
|
29 |
import org.distorted.examples.R; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
class FlatBlurSurfaceView extends GLSurfaceView |
|
34 |
{ |
|
35 |
private FlatBlurRenderer mRenderer; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
public FlatBlurSurfaceView(Context context, AttributeSet attrs) |
|
40 |
{ |
|
41 |
super(context, attrs); |
|
42 |
|
|
43 |
if(!isInEditMode()) |
|
44 |
{ |
|
45 |
mRenderer = new FlatBlurRenderer(this); |
|
46 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
47 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
48 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
49 |
setRenderer(mRenderer); |
|
50 |
Toast.makeText(context, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show(); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
|
|
56 |
public FlatBlurRenderer getRenderer() |
|
57 |
{ |
|
58 |
return mRenderer; |
|
59 |
} |
|
60 |
} |
|
61 |
|
src/main/res/layout/flatblurlayout.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.flatblur.FlatBlurSurfaceView |
|
8 |
android:id="@+id/flatblurSurfaceView" |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="0dp" |
|
11 |
android:layout_weight="1" /> |
|
12 |
|
|
13 |
<LinearLayout |
|
14 |
android:orientation="horizontal" |
|
15 |
android:layout_width="match_parent" |
|
16 |
android:layout_height="wrap_content" |
|
17 |
android:gravity="center"> |
|
18 |
|
|
19 |
<CheckBox |
|
20 |
android:id="@+id/flatblurEnableBlur" |
|
21 |
android:layout_width="0dp" |
|
22 |
android:layout_height="match_parent" |
|
23 |
android:layout_weight="1" |
|
24 |
android:onClick="enableBlur" |
|
25 |
android:checked="false"/> |
|
26 |
|
|
27 |
<SeekBar |
|
28 |
android:id="@+id/flatblurBlurStrength" |
|
29 |
android:layout_width="0dp" |
|
30 |
android:layout_height="match_parent" |
|
31 |
android:layout_weight="2" |
|
32 |
android:layout_gravity="center_vertical" |
|
33 |
android:layout_margin="5dp"/> |
|
34 |
|
|
35 |
</LinearLayout> |
|
36 |
|
|
37 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
215 | 215 |
<string name="example_singlemesh_subtitle">Use the new MeshJoined + MeshBase.apply() to create a single, movable Mesh representing a 2x2x2 RubikCube.</string> |
216 | 216 |
<string name="example_meshfile">Mesh from File</string> |
217 | 217 |
<string name="example_meshfile_subtitle">Explore Distorted\'s own Mesh format, dmesh. Open .dmesh files and explore their contents.</string> |
218 |
<string name="example_flatblur">Flat Blur</string> |
|
219 |
<string name="example_flatblur_subtitle">Unit test to see two partially obstructing flat objects, one of them blurred.</string> |
|
218 | 220 |
|
219 | 221 |
<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> |
220 | 222 |
<string name="example_rotate_toast">Rotate the scene by swiping the screen</string> |
Also available in: Unified diff
New Flat Blur unit test.