Revision 1746198f
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/fbo/FBOActivity.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.fbo; |
21 | 21 |
|
22 |
import org.distorted.examples.R; |
|
22 | 23 |
import org.distorted.library.Distorted; |
23 | 24 |
|
24 | 25 |
import android.app.Activity; |
25 | 26 |
import android.os.Bundle; |
27 |
import android.view.View; |
|
26 | 28 |
|
27 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
28 | 30 |
|
29 | 31 |
public class FBOActivity extends Activity |
30 | 32 |
{ |
31 |
private FBOSurfaceView mView; |
|
32 |
|
|
33 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 34 |
|
35 | 35 |
@Override |
36 | 36 |
protected void onCreate(Bundle icicle) |
37 | 37 |
{ |
38 | 38 |
super.onCreate(icicle); |
39 |
mView = new FBOSurfaceView(this); |
|
40 |
setContentView(mView); |
|
39 |
setContentView(R.layout.fbolayout); |
|
41 | 40 |
} |
42 | 41 |
|
43 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
45 | 44 |
@Override |
46 | 45 |
protected void onPause() |
47 | 46 |
{ |
48 |
mView.onPause(); |
|
47 |
FBOSurfaceView view = (FBOSurfaceView) this.findViewById(R.id.fboSurfaceView); |
|
48 |
|
|
49 |
view.onPause(); |
|
49 | 50 |
super.onPause(); |
50 | 51 |
} |
51 | 52 |
|
... | ... | |
54 | 55 |
@Override |
55 | 56 |
protected void onResume() |
56 | 57 |
{ |
58 |
FBOSurfaceView view = (FBOSurfaceView) this.findViewById(R.id.fboSurfaceView); |
|
59 |
|
|
57 | 60 |
super.onResume(); |
58 |
mView.onResume();
|
|
61 |
view.onResume();
|
|
59 | 62 |
} |
60 | 63 |
|
61 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
66 | 69 |
Distorted.onDestroy(); |
67 | 70 |
super.onDestroy(); |
68 | 71 |
} |
69 |
|
|
72 |
|
|
73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 |
|
|
75 |
public void DepthYes(View v) |
|
76 |
{ |
|
77 |
FBOSurfaceView view = (FBOSurfaceView) this.findViewById(R.id.fboSurfaceView); |
|
78 |
FBORenderer renderer = view.getRenderer(); |
|
79 |
|
|
80 |
renderer.setDepth(true); |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
public void DepthNo(View v) |
|
86 |
{ |
|
87 |
FBOSurfaceView view = (FBOSurfaceView) this.findViewById(R.id.fboSurfaceView); |
|
88 |
FBORenderer renderer = view.getRenderer(); |
|
89 |
|
|
90 |
renderer.setDepth(false); |
|
91 |
} |
|
70 | 92 |
} |
src/main/java/org/distorted/examples/fbo/FBORenderer.java | ||
---|---|---|
64 | 64 |
mScreen = new DistortedFramebuffer(0); |
65 | 65 |
} |
66 | 66 |
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
void setDepth(boolean depth) |
|
70 |
{ |
|
71 |
if( mRoot!=null ) |
|
72 |
{ |
|
73 |
DistortedFramebuffer tmp = mRoot.getFramebuffer(); |
|
74 |
tmp.setDepthAttachment(depth); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
67 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 79 |
|
69 |
public void onDrawFrame(GL10 glUnused)
|
|
80 |
public void onDrawFrame(GL10 glUnused)
|
|
70 | 81 |
{ |
71 | 82 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
72 | 83 |
mScreen.renderTo(mRoot,System.currentTimeMillis()); |
... | ... | |
74 | 85 |
|
75 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
76 | 87 |
|
77 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
88 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
78 | 89 |
{ |
79 | 90 |
mEffects.abortEffects(EffectTypes.MATRIX); |
80 | 91 |
|
... | ... | |
100 | 111 |
|
101 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
102 | 113 |
|
103 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
114 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
104 | 115 |
{ |
105 | 116 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
106 | 117 |
|
... | ... | |
140 | 151 |
mRoot = new DistortedTree(lisa, mEffects,new MeshFlat(1,1)); |
141 | 152 |
mRoot.attach(grid,gridEffects,new MeshCubes(10,10,false)); |
142 | 153 |
|
143 |
DistortedFramebuffer tmp = mRoot.getFramebuffer(); |
|
144 |
tmp.setDepthAttachment(true); |
|
145 |
|
|
146 | 154 |
float factor = lisaWidth/(2.0f*gridWidth); |
147 | 155 |
|
148 | 156 |
gridEffects.move( new Static3D( (lisaWidth-factor*gridWidth)/2,(lisaHeight-factor*gridHeight)/2,0) ); |
src/main/java/org/distorted/examples/fbo/FBOSurfaceView.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.content.Context; |
23 | 23 |
import android.opengl.GLSurfaceView; |
24 |
import android.util.AttributeSet; |
|
24 | 25 |
|
25 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
26 | 27 |
|
27 | 28 |
class FBOSurfaceView extends GLSurfaceView |
28 | 29 |
{ |
30 |
private FBORenderer mRenderer; |
|
31 |
|
|
29 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 33 |
|
31 |
public FBOSurfaceView(Context context) |
|
34 |
public FBOSurfaceView(Context c, AttributeSet attrs) |
|
35 |
{ |
|
36 |
super(c, attrs); |
|
37 |
|
|
38 |
if(!isInEditMode()) |
|
39 |
{ |
|
40 |
setEGLContextClientVersion(2); |
|
41 |
mRenderer = new FBORenderer(this); |
|
42 |
setRenderer(mRenderer); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
public FBORenderer getRenderer() |
|
32 | 49 |
{ |
33 |
super(context); |
|
34 |
setEGLContextClientVersion(2); |
|
35 |
setRenderer(new FBORenderer(this)); |
|
50 |
return mRenderer; |
|
36 | 51 |
} |
37 | 52 |
} |
38 | 53 |
|
src/main/res/layout/fbolayout.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.fbo.FBOSurfaceView |
|
8 |
android:id="@+id/fboSurfaceView" |
|
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="vertical" > |
|
19 |
|
|
20 |
<RadioGroup |
|
21 |
android:id="@+id/radioGroup1" |
|
22 |
android:layout_width="match_parent" |
|
23 |
android:layout_height="wrap_content" |
|
24 |
android:orientation="horizontal" > |
|
25 |
|
|
26 |
<RadioButton |
|
27 |
android:id="@+id/deformDistortButton" |
|
28 |
android:layout_width="wrap_content" |
|
29 |
android:layout_height="wrap_content" |
|
30 |
android:onClick="DepthYes" |
|
31 |
android:text="@string/DepthYes" /> |
|
32 |
|
|
33 |
<RadioButton |
|
34 |
android:id="@+id/deformDeformButton" |
|
35 |
android:layout_width="wrap_content" |
|
36 |
android:layout_height="wrap_content" |
|
37 |
android:checked="true" |
|
38 |
android:onClick="DepthNo" |
|
39 |
android:text="@string/DepthNo" /> |
|
40 |
|
|
41 |
</RadioGroup> |
|
42 |
|
|
43 |
</LinearLayout> |
|
44 |
|
|
45 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
57 | 57 |
<string name="length">Length</string> |
58 | 58 |
<string name="angleA">Alpha</string> |
59 | 59 |
<string name="angleB">Beta</string> |
60 |
<string name="DepthYes">Depth</string> |
|
61 |
<string name="DepthNo">No Depth</string> |
|
60 | 62 |
|
61 | 63 |
<string name="radius_placeholder">Radius: %1$s</string> |
62 | 64 |
<string name="noise_placeholder">Noise %1$s</string> |
Also available in: Unified diff
FBO APP: add dynamic adding/removing the DEPTH attachment.