Revision 32d08f39
Added by Leszek Koltunski over 7 years ago
src/main/AndroidManifest.xml | ||
---|---|---|
45 | 45 |
<activity android:name=".mirror.MirrorActivity"/> |
46 | 46 |
<activity android:name=".blur.BlurActivity"/> |
47 | 47 |
<activity android:name=".multiblur.MultiblurActivity"/> |
48 |
<activity android:name=".feedback.FeedbackActivity"/>
|
|
48 |
<activity android:name=".stencil.StencilActivity"/>
|
|
49 | 49 |
</application> |
50 | 50 |
</manifest> |
src/main/java/org/distorted/examples/TableOfContents.java | ||
---|---|---|
63 | 63 |
import org.distorted.examples.mirror.MirrorActivity; |
64 | 64 |
import org.distorted.examples.blur.BlurActivity; |
65 | 65 |
import org.distorted.examples.multiblur.MultiblurActivity; |
66 |
import org.distorted.examples.feedback.FeedbackActivity;
|
|
66 |
import org.distorted.examples.stencil.StencilActivity;
|
|
67 | 67 |
|
68 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
69 | 69 |
|
... | ... | |
349 | 349 |
|
350 | 350 |
{ |
351 | 351 |
final Map<String, Object> item = new HashMap<>(); |
352 |
item.put(ITEM_IMAGE, R.drawable.icon_example_feedback);
|
|
353 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_feedback));
|
|
354 |
item.put(ITEM_SUBTITLE, getText(R.string.example_feedback_subtitle));
|
|
352 |
item.put(ITEM_IMAGE, R.drawable.icon_example_stencil);
|
|
353 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_stencil));
|
|
354 |
item.put(ITEM_SUBTITLE, getText(R.string.example_stencil_subtitle));
|
|
355 | 355 |
data.add(item); |
356 |
activityMapping.put(i++, FeedbackActivity.class);
|
|
356 |
activityMapping.put(i++, StencilActivity.class);
|
|
357 | 357 |
} |
358 | 358 |
|
359 | 359 |
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/feedback/FeedbackActivity.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.feedback; |
|
21 |
|
|
22 |
import android.app.Activity; |
|
23 |
import android.os.Bundle; |
|
24 |
|
|
25 |
import org.distorted.library.Distorted; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
public class FeedbackActivity extends Activity |
|
30 |
{ |
|
31 |
private FeedbackSurfaceView mView; |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
@Override |
|
36 |
protected void onCreate(Bundle icicle) |
|
37 |
{ |
|
38 |
super.onCreate(icicle); |
|
39 |
mView = new FeedbackSurfaceView(this); |
|
40 |
setContentView(mView); |
|
41 |
} |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
@Override |
|
46 |
protected void onPause() |
|
47 |
{ |
|
48 |
mView.onPause(); |
|
49 |
Distorted.onPause(); |
|
50 |
super.onPause(); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void onResume() |
|
57 |
{ |
|
58 |
super.onResume(); |
|
59 |
mView.onResume(); |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
@Override |
|
65 |
protected void onDestroy() |
|
66 |
{ |
|
67 |
Distorted.onDestroy(); |
|
68 |
super.onDestroy(); |
|
69 |
} |
|
70 |
|
|
71 |
} |
src/main/java/org/distorted/examples/feedback/FeedbackRenderer.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.feedback; |
|
21 |
|
|
22 |
import android.content.res.Resources; |
|
23 |
import android.opengl.GLES30; |
|
24 |
import android.opengl.GLSurfaceView; |
|
25 |
|
|
26 |
import org.distorted.library.Distorted; |
|
27 |
import org.distorted.library.program.DistortedProgram; |
|
28 |
|
|
29 |
import java.io.InputStream; |
|
30 |
import java.nio.Buffer; |
|
31 |
import java.nio.ByteBuffer; |
|
32 |
import java.nio.ByteOrder; |
|
33 |
import java.nio.FloatBuffer; |
|
34 |
|
|
35 |
import javax.microedition.khronos.egl.EGLConfig; |
|
36 |
import javax.microedition.khronos.opengles.GL10; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
class FeedbackRenderer implements GLSurfaceView.Renderer |
|
41 |
{ |
|
42 |
private final int BYTESFLOAT = 4; |
|
43 |
private final int POSITION = 3; |
|
44 |
|
|
45 |
private final boolean USEPOINTS=false; |
|
46 |
|
|
47 |
private GLSurfaceView mView; |
|
48 |
private DistortedProgram mFeedbackProgram; |
|
49 |
private int mVertices; |
|
50 |
private int[] mVBO, mTBO; |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
FeedbackRenderer(GLSurfaceView v) |
|
55 |
{ |
|
56 |
mView = v; |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
|
61 |
public void onDrawFrame(GL10 glUnused) |
|
62 |
{ |
|
63 |
mFeedbackProgram.useProgram(); |
|
64 |
|
|
65 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVBO[0]); |
|
66 |
GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[0], POSITION, GLES30.GL_FLOAT, false, 0, 0); |
|
67 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mTBO[0]); |
|
68 |
|
|
69 |
GLES30.glEnable(GLES30.GL_RASTERIZER_DISCARD); |
|
70 |
GLES30.glBeginTransformFeedback( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLES); |
|
71 |
GLES30.glDrawArrays( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLES, 0, mVertices); |
|
72 |
|
|
73 |
int error = GLES30.glGetError(); |
|
74 |
|
|
75 |
if( error != GLES30.GL_NO_ERROR ) |
|
76 |
{ |
|
77 |
throw new RuntimeException("DrawArrays: glError 0x" + Integer.toHexString(error)); |
|
78 |
} |
|
79 |
|
|
80 |
GLES30.glEndTransformFeedback(); |
|
81 |
GLES30.glDisable(GLES30.GL_RASTERIZER_DISCARD); |
|
82 |
GLES30.glFlush(); |
|
83 |
|
|
84 |
Buffer mappedBuffer = GLES30.glMapBufferRange(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mVertices*POSITION*BYTESFLOAT, GLES30.GL_MAP_READ_BIT); |
|
85 |
FloatBuffer fb = ((ByteBuffer) mappedBuffer).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
86 |
String msg = ""; |
|
87 |
|
|
88 |
for(int i=0; i<mVertices*POSITION; i++) msg += (" "+fb.get(i)); |
|
89 |
|
|
90 |
android.util.Log.d( "Feedback", msg); |
|
91 |
|
|
92 |
GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER); |
|
93 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); |
|
94 |
} |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
99 |
{ |
|
100 |
|
|
101 |
} |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
|
105 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
106 |
{ |
|
107 |
try |
|
108 |
{ |
|
109 |
Distorted.onCreate(mView.getContext()); |
|
110 |
} |
|
111 |
catch(Exception ex) |
|
112 |
{ |
|
113 |
android.util.Log.e("Feedback", ex.getMessage() ); |
|
114 |
} |
|
115 |
|
|
116 |
final Resources resources = mView.getContext().getResources(); |
|
117 |
final InputStream vertStream = resources.openRawResource(org.distorted.library.R.raw.feedback_vertex_shader); |
|
118 |
final InputStream fragStream = resources.openRawResource(org.distorted.library.R.raw.feedback_fragment_shader); |
|
119 |
|
|
120 |
int glsl = 300; |
|
121 |
String header= "#version 300 es\n"; |
|
122 |
String[] feedback = { "outValue" }; |
|
123 |
|
|
124 |
try |
|
125 |
{ |
|
126 |
mFeedbackProgram = new DistortedProgram(vertStream,fragStream, header, header, glsl, feedback ); |
|
127 |
} |
|
128 |
catch(Exception ex) |
|
129 |
{ |
|
130 |
android.util.Log.e("Feedback", "exception creating feedback program: "+ex.getMessage()); |
|
131 |
} |
|
132 |
|
|
133 |
float[] floatData = { 1.0f, 4.0f, 9.0f, |
|
134 |
16.0f, 25.0f, 36.0f, |
|
135 |
49.0f, 64.0f, 81.0f, |
|
136 |
100.0f,121.0f,144.0f, |
|
137 |
1.0f, 4.0f, 9.0f, |
|
138 |
16.0f, 25.0f, 36.0f |
|
139 |
}; |
|
140 |
|
|
141 |
mVertices = floatData.length/POSITION; |
|
142 |
FloatBuffer data = ByteBuffer.allocateDirect(mVertices*POSITION*BYTESFLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
143 |
data.put(floatData).position(0); |
|
144 |
|
|
145 |
mVBO = new int[1]; |
|
146 |
GLES30.glGenBuffers(1, mVBO, 0); |
|
147 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVBO[0]); |
|
148 |
GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, mVertices*POSITION*BYTESFLOAT, data, GLES30.GL_STATIC_DRAW); |
|
149 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); |
|
150 |
|
|
151 |
mTBO = new int[1]; |
|
152 |
GLES30.glGenBuffers(1, mTBO, 0); |
|
153 |
GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, mTBO[0]); |
|
154 |
GLES30.glBufferData(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, mVertices*POSITION*BYTESFLOAT, null, GLES30.GL_STATIC_READ); |
|
155 |
GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0); |
|
156 |
} |
|
157 |
} |
src/main/java/org/distorted/examples/feedback/FeedbackSurfaceView.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.feedback; |
|
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 FeedbackSurfaceView extends GLSurfaceView |
|
30 |
{ |
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public FeedbackSurfaceView(Context context) |
|
34 |
{ |
|
35 |
super(context); |
|
36 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
37 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
38 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
39 |
setRenderer(new FeedbackRenderer(this)); |
|
40 |
} |
|
41 |
} |
|
42 |
|
src/main/java/org/distorted/examples/stencil/StencilActivity.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.stencil; |
|
21 |
|
|
22 |
import android.app.Activity; |
|
23 |
import android.os.Bundle; |
|
24 |
|
|
25 |
import org.distorted.library.Distorted; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
public class StencilActivity extends Activity |
|
30 |
{ |
|
31 |
private StencilSurfaceView mView; |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
@Override |
|
36 |
protected void onCreate(Bundle icicle) |
|
37 |
{ |
|
38 |
super.onCreate(icicle); |
|
39 |
mView = new StencilSurfaceView(this); |
|
40 |
setContentView(mView); |
|
41 |
} |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
@Override |
|
46 |
protected void onPause() |
|
47 |
{ |
|
48 |
mView.onPause(); |
|
49 |
Distorted.onPause(); |
|
50 |
super.onPause(); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void onResume() |
|
57 |
{ |
|
58 |
super.onResume(); |
|
59 |
mView.onResume(); |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
@Override |
|
65 |
protected void onDestroy() |
|
66 |
{ |
|
67 |
Distorted.onDestroy(); |
|
68 |
super.onDestroy(); |
|
69 |
} |
|
70 |
|
|
71 |
} |
src/main/java/org/distorted/examples/stencil/StencilRenderer.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.stencil; |
|
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.Distorted; |
|
28 |
import org.distorted.library.DistortedEffects; |
|
29 |
import org.distorted.library.DistortedScreen; |
|
30 |
import org.distorted.library.DistortedTexture; |
|
31 |
import org.distorted.library.EffectNames; |
|
32 |
import org.distorted.library.EffectTypes; |
|
33 |
import org.distorted.library.MeshCubes; |
|
34 |
import org.distorted.library.MeshFlat; |
|
35 |
import org.distorted.library.MeshObject; |
|
36 |
import org.distorted.library.type.Dynamic1D; |
|
37 |
import org.distorted.library.type.Static1D; |
|
38 |
import org.distorted.library.type.Static3D; |
|
39 |
|
|
40 |
import java.io.IOException; |
|
41 |
import java.io.InputStream; |
|
42 |
|
|
43 |
import javax.microedition.khronos.egl.EGLConfig; |
|
44 |
import javax.microedition.khronos.opengles.GL10; |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
class StencilRenderer implements GLSurfaceView.Renderer |
|
49 |
{ |
|
50 |
private GLSurfaceView mView; |
|
51 |
private DistortedScreen mScreen; |
|
52 |
private DistortedTexture mCubeTex, mFloorTex; |
|
53 |
private DistortedEffects mCube1Effects, mCube2Effects, mFloorEffects; |
|
54 |
private MeshObject mCubeMesh, mFloorMesh; |
|
55 |
private int bmpHeight, bmpWidth; |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
StencilRenderer(GLSurfaceView v) |
|
60 |
{ |
|
61 |
mView = v; |
|
62 |
|
|
63 |
mCubeMesh = new MeshCubes(1,1,false); |
|
64 |
mFloorMesh = new MeshFlat(1,1); |
|
65 |
|
|
66 |
mCubeTex = new DistortedTexture(1,1); |
|
67 |
mFloorTex = new DistortedTexture(1,1); |
|
68 |
|
|
69 |
mCube1Effects = new DistortedEffects(); |
|
70 |
mCube2Effects = new DistortedEffects(); |
|
71 |
mFloorEffects = new DistortedEffects(); |
|
72 |
|
|
73 |
mCube2Effects.brightness(new Static1D(0.5f)); |
|
74 |
|
|
75 |
mScreen = new DistortedScreen(); |
|
76 |
mScreen.attach(mCubeTex ,mCube1Effects,mCubeMesh ); |
|
77 |
mScreen.attach(mFloorTex,mFloorEffects,mFloorMesh); |
|
78 |
mScreen.attach(mCubeTex ,mCube2Effects,mCubeMesh ); |
|
79 |
|
|
80 |
mScreen.glClearColor(1.0f,1.0f,1.0f,1.0f); |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
public void onDrawFrame(GL10 glUnused) |
|
86 |
{ |
|
87 |
mScreen.render(System.currentTimeMillis()); |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
93 |
{ |
|
94 |
float cw = mCubeTex.getWidth(); |
|
95 |
float ch = mCubeTex.getHeight(); |
|
96 |
float cd = mCubeTex.getDepth(mCubeMesh); |
|
97 |
|
|
98 |
float fw = mFloorTex.getWidth(); |
|
99 |
float fh = mFloorTex.getHeight(); |
|
100 |
float fd = mFloorTex.getDepth(mFloorMesh); |
|
101 |
|
|
102 |
float cubeScale = 0.4f*(width>height ? height/ch:width/cw); |
|
103 |
float floorScale= 0.8f*(width>height ? height/fh:width/fw); |
|
104 |
|
|
105 |
Static3D cubeCenter = new Static3D(cw/2,ch ,-cd/2); |
|
106 |
Static3D floorCenter= new Static3D(fw/2,fh/2,-fd/2); |
|
107 |
|
|
108 |
Static3D axisX = new Static3D(1,0,0); |
|
109 |
Static3D axisY = new Static3D(0,1,0); |
|
110 |
Static3D axisZ = new Static3D(0,0,1); |
|
111 |
|
|
112 |
Dynamic1D rotDyn = new Dynamic1D(5000,0.0f); |
|
113 |
rotDyn.setMode(Dynamic1D.MODE_JUMP); |
|
114 |
rotDyn.add(new Static1D( 0)); |
|
115 |
rotDyn.add(new Static1D(360)); |
|
116 |
|
|
117 |
float angle = 30.0f; |
|
118 |
|
|
119 |
Static1D rotSt1 = new Static1D(angle); |
|
120 |
Static1D rotSt2 = new Static1D(angle-90.0f); |
|
121 |
|
|
122 |
mCube1Effects.abortEffects(EffectTypes.MATRIX); |
|
123 |
mCube1Effects.move( new Static3D( (width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2) ); |
|
124 |
mCube1Effects.scale(cubeScale); |
|
125 |
mCube1Effects.rotate(rotSt1, axisX, cubeCenter); |
|
126 |
mCube1Effects.rotate(rotDyn, axisY, cubeCenter); |
|
127 |
|
|
128 |
mCube2Effects.abortEffects(EffectTypes.MATRIX); |
|
129 |
mCube2Effects.move( new Static3D( (width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2) ); |
|
130 |
mCube2Effects.scale(cubeScale); |
|
131 |
mCube2Effects.rotate(rotSt1, axisX, cubeCenter); |
|
132 |
mCube2Effects.rotate(rotDyn, axisY, cubeCenter); |
|
133 |
mCube2Effects.scale(new Static3D(1,-1,1) ); |
|
134 |
mCube2Effects.move( new Static3D( 0, -2*ch , 0) ); |
|
135 |
|
|
136 |
mFloorEffects.abortEffects(EffectTypes.MATRIX); |
|
137 |
mFloorEffects.move( new Static3D( (width-floorScale*fw)/2 ,height/2-floorScale*fh/2, floorScale*fd/2) ); |
|
138 |
mFloorEffects.scale(floorScale); |
|
139 |
mFloorEffects.rotate(rotSt2, axisX, floorCenter); |
|
140 |
mFloorEffects.rotate(rotDyn, axisZ, floorCenter); |
|
141 |
|
|
142 |
mScreen.resize(width, height); |
|
143 |
} |
|
144 |
|
|
145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 |
|
|
147 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
148 |
{ |
|
149 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.cat); |
|
150 |
Bitmap bitmap; |
|
151 |
|
|
152 |
try |
|
153 |
{ |
|
154 |
bitmap = BitmapFactory.decodeStream(is); |
|
155 |
} |
|
156 |
finally |
|
157 |
{ |
|
158 |
try |
|
159 |
{ |
|
160 |
is.close(); |
|
161 |
} |
|
162 |
catch(IOException e) { } |
|
163 |
} |
|
164 |
|
|
165 |
bmpHeight = bitmap.getHeight(); |
|
166 |
bmpWidth = bitmap.getWidth(); |
|
167 |
|
|
168 |
mCubeTex.setTexture(bitmap); |
|
169 |
mFloorTex.setColor(0xff000000); // ARGB |
|
170 |
|
|
171 |
DistortedEffects.enableEffect(EffectNames.BRIGHTNESS); |
|
172 |
|
|
173 |
try |
|
174 |
{ |
|
175 |
Distorted.onCreate(mView.getContext()); |
|
176 |
} |
|
177 |
catch(Exception ex) |
|
178 |
{ |
|
179 |
android.util.Log.e("Stencil", ex.getMessage() ); |
|
180 |
} |
|
181 |
} |
|
182 |
} |
src/main/java/org/distorted/examples/stencil/StencilSurfaceView.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.stencil; |
|
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 StencilSurfaceView extends GLSurfaceView |
|
30 |
{ |
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public StencilSurfaceView(Context context) |
|
34 |
{ |
|
35 |
super(context); |
|
36 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
37 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
38 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
39 |
setRenderer(new StencilRenderer(this)); |
|
40 |
} |
|
41 |
} |
|
42 |
|
src/main/res/values/strings.xml | ||
---|---|---|
141 | 141 |
<string name="example_blur_subtitle">Postprocessing effect: Blur.</string> |
142 | 142 |
<string name="example_multiblur">Multiblur</string> |
143 | 143 |
<string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</string> |
144 |
<string name="example_feedback">Transform Feedback</string>
|
|
145 |
<string name="example_feedback_subtitle">Transform Feedback test.</string>
|
|
144 |
<string name="example_stencil">Stencil Buffer</string>
|
|
145 |
<string name="example_stencil_subtitle">Implement the classic stencil example from https://open.gl/depthstencils</string>
|
|
146 | 146 |
|
147 | 147 |
<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> |
148 | 148 |
<string name="example_rotate_toast">Rotate the scene by swiping the screen</string> |
Also available in: Unified diff
Beginnings of Stencil App.