Revision 29aba2d1
Added by Leszek Koltunski over 6 years ago
src/main/java/org/distorted/examples/transparency/TransparencyActivity.java | ||
---|---|---|
25 | 25 |
import android.view.View; |
26 | 26 |
import android.widget.AdapterView; |
27 | 27 |
import android.widget.ArrayAdapter; |
28 |
import android.widget.CheckBox; |
|
28 | 29 |
import android.widget.SeekBar; |
29 | 30 |
import android.widget.Spinner; |
30 | 31 |
|
... | ... | |
45 | 46 |
super.onCreate(savedState); |
46 | 47 |
setContentView(R.layout.transparencylayout); |
47 | 48 |
|
48 |
SeekBar barRed = (SeekBar)findViewById(R.id.transparencySeekRed);
|
|
49 |
SeekBar barYellow = (SeekBar)findViewById(R.id.transparencySeekYellow);
|
|
49 |
SeekBar barRed = findViewById(R.id.transparencySeekRed); |
|
50 |
SeekBar barYellow = findViewById(R.id.transparencySeekYellow); |
|
50 | 51 |
|
51 | 52 |
barRed.setOnSeekBarChangeListener(this); |
52 | 53 |
barYellow.setOnSeekBarChangeListener(this); |
... | ... | |
58 | 59 |
privateRenderFirst(0); |
59 | 60 |
} |
60 | 61 |
|
61 |
Spinner typeSpinner = (Spinner)findViewById(R.id.transparency_spinnerFirst);
|
|
62 |
Spinner typeSpinner = findViewById(R.id.transparency_spinnerFirst); |
|
62 | 63 |
typeSpinner.setOnItemSelectedListener(this); |
63 | 64 |
|
64 | 65 |
String[] objectType = new String[] {"First: Red", "First: Yellow"}; |
... | ... | |
67 | 68 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
68 | 69 |
typeSpinner.setAdapter(adapterType); |
69 | 70 |
|
70 |
Spinner bitmapSpinner = (Spinner)findViewById(R.id.transparency_spinnerMode);
|
|
71 |
Spinner bitmapSpinner = findViewById(R.id.transparency_spinnerMode); |
|
71 | 72 |
bitmapSpinner.setOnItemSelectedListener(this); |
72 | 73 |
|
73 | 74 |
String[] objectBitmap = new String[] { "Render: Normal", "Render: OIT" }; |
... | ... | |
101 | 102 |
@Override |
102 | 103 |
protected void onPause() |
103 | 104 |
{ |
104 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.transparencySurfaceView);
|
|
105 |
GLSurfaceView view = this.findViewById(R.id.transparencySurfaceView); |
|
105 | 106 |
view.onPause(); |
106 | 107 |
Distorted.onPause(); |
107 | 108 |
super.onPause(); |
... | ... | |
113 | 114 |
protected void onResume() |
114 | 115 |
{ |
115 | 116 |
super.onResume(); |
116 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.transparencySurfaceView);
|
|
117 |
GLSurfaceView view = this.findViewById(R.id.transparencySurfaceView); |
|
117 | 118 |
view.onResume(); |
118 | 119 |
} |
119 | 120 |
|
... | ... | |
152 | 153 |
{ |
153 | 154 |
switch (bar.getId()) |
154 | 155 |
{ |
155 |
case R.id.transparencySeekRed: TransparencySurfaceView view0 = (TransparencySurfaceView) this.findViewById(R.id.transparencySurfaceView);
|
|
156 |
case R.id.transparencySeekRed: TransparencySurfaceView view0 = this.findViewById(R.id.transparencySurfaceView); |
|
156 | 157 |
view0.getRenderer().setTransparency(0, (float)progress/100 ); |
157 | 158 |
break; |
158 |
case R.id.transparencySeekYellow: TransparencySurfaceView view1 = (TransparencySurfaceView) this.findViewById(R.id.transparencySurfaceView);
|
|
159 |
case R.id.transparencySeekYellow: TransparencySurfaceView view1 = this.findViewById(R.id.transparencySurfaceView); |
|
159 | 160 |
view1.getRenderer().setTransparency(1, (float)progress/100 ); |
160 | 161 |
break; |
161 | 162 |
} |
... | ... | |
173 | 174 |
|
174 | 175 |
private void setRenderModeToOIT(boolean oit) |
175 | 176 |
{ |
176 |
TransparencySurfaceView view = (TransparencySurfaceView) this.findViewById(R.id.transparencySurfaceView);
|
|
177 |
TransparencySurfaceView view = this.findViewById(R.id.transparencySurfaceView); |
|
177 | 178 |
TransparencyRenderer renderer= view.getRenderer(); |
178 | 179 |
|
179 | 180 |
renderer.setRenderModeToOIT(oit); |
... | ... | |
183 | 184 |
|
184 | 185 |
private void privateRenderFirst(int index) |
185 | 186 |
{ |
186 |
TransparencySurfaceView view = (TransparencySurfaceView) this.findViewById(R.id.transparencySurfaceView);
|
|
187 |
TransparencySurfaceView view = this.findViewById(R.id.transparencySurfaceView); |
|
187 | 188 |
TransparencyRenderer renderer= view.getRenderer(); |
188 | 189 |
|
189 | 190 |
renderer.setRenderFirst(index); |
190 | 191 |
mRenderFirst = index; |
191 | 192 |
} |
193 |
|
|
194 |
|
|
195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
196 |
|
|
197 |
public void onClick(View view) |
|
198 |
{ |
|
199 |
CheckBox box = (CheckBox)view; |
|
200 |
boolean checked = box.isChecked(); |
|
201 |
TransparencySurfaceView sView = this.findViewById(R.id.transparencySurfaceView); |
|
202 |
|
|
203 |
switch(box.getId()) |
|
204 |
{ |
|
205 |
case R.id.transparencyCheckBox0 : sView.getRenderer().setPostprocess(0,checked); break; |
|
206 |
case R.id.transparencyCheckBox1 : sView.getRenderer().setPostprocess(1,checked); break; |
|
207 |
} |
|
208 |
} |
|
192 | 209 |
} |
src/main/java/org/distorted/examples/transparency/TransparencyRenderer.java | ||
---|---|---|
61 | 61 |
private Static1D[] mAlphaVector; |
62 | 62 |
private DistortedScreen mScreen; |
63 | 63 |
private Static3D mMove, mScale, mCenter; |
64 |
private PostprocessEffectBlur[] mBlur; |
|
65 |
private boolean[] mBlurApplied; |
|
66 |
private DistortedEffects[] mEffects; |
|
64 | 67 |
|
65 | 68 |
Static4D mQuat1, mQuat2; |
66 | 69 |
int mScreenMin; |
... | ... | |
83 | 86 |
mAlphaVector = new Static1D[NUM_OBJECTS]; |
84 | 87 |
mNode = new DistortedNode[NUM_OBJECTS]; |
85 | 88 |
mTex = new DistortedTexture[NUM_OBJECTS]; |
89 |
mBlur = new PostprocessEffectBlur[NUM_OBJECTS]; |
|
90 |
mEffects = new DistortedEffects[NUM_OBJECTS]; |
|
91 |
mBlurApplied = new boolean[NUM_OBJECTS]; |
|
86 | 92 |
|
87 | 93 |
FragmentEffectAlpha[] alpha = new FragmentEffectAlpha[NUM_OBJECTS]; |
88 |
DistortedEffects[] effects = new DistortedEffects[NUM_OBJECTS]; |
|
89 |
PostprocessEffectBlur[] blur = new PostprocessEffectBlur[NUM_OBJECTS]; |
|
90 | 94 |
|
91 | 95 |
mMove = new Static3D(0,0,0); |
92 | 96 |
mScale = new Static3D(1.0f,1.0f,1.0f); |
... | ... | |
103 | 107 |
mTex[i] = new DistortedTexture(OBJ_SIZE,OBJ_SIZE); |
104 | 108 |
mMoveVector[i] = new Static3D(0,0,0); |
105 | 109 |
mAlphaVector[i] = new Static1D(0.5f); |
110 |
mBlur[i] = new PostprocessEffectBlur(new Static1D(0)); |
|
111 |
mBlurApplied[i] = true; |
|
106 | 112 |
alpha[i] = new FragmentEffectAlpha(mAlphaVector[i]); |
107 |
blur[i] = new PostprocessEffectBlur(new Static1D(0)); |
|
108 |
effects[i] = new DistortedEffects(); |
|
109 |
|
|
110 |
effects[i].apply(blur[i]); |
|
111 |
effects[i].apply(alpha[i]); |
|
112 |
effects[i].apply(moveEffect); |
|
113 |
effects[i].apply(scaleEffect); |
|
114 |
effects[i].apply(quatEffect1); |
|
115 |
effects[i].apply(quatEffect2); |
|
116 |
effects[i].apply(new MatrixEffectMove(mMoveVector[i])); |
|
117 |
|
|
118 |
mNode[i] = new DistortedNode(mTex[i], effects[i], mesh ); |
|
113 |
mEffects[i] = new DistortedEffects(); |
|
114 |
|
|
115 |
mEffects[i].apply(mBlur[i]); |
|
116 |
mEffects[i].apply(alpha[i]); |
|
117 |
mEffects[i].apply(moveEffect); |
|
118 |
mEffects[i].apply(scaleEffect); |
|
119 |
mEffects[i].apply(quatEffect1); |
|
120 |
mEffects[i].apply(quatEffect2); |
|
121 |
mEffects[i].apply(new MatrixEffectMove(mMoveVector[i])); |
|
122 |
|
|
123 |
mNode[i] = new DistortedNode(mTex[i], mEffects[i], mesh ); |
|
119 | 124 |
mScreen.attach(mNode[i]); |
120 | 125 |
} |
121 | 126 |
} |
122 | 127 |
|
128 |
|
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 |
|
|
131 |
void setPostprocess(int object, boolean doIt) |
|
132 |
{ |
|
133 |
if( object>=0 && object<NUM_OBJECTS) |
|
134 |
{ |
|
135 |
if( doIt && !mBlurApplied[object] ) |
|
136 |
{ |
|
137 |
mBlurApplied[object] = true; |
|
138 |
mEffects[object].apply(mBlur[object]); |
|
139 |
} |
|
140 |
if( !doIt && mBlurApplied[object] ) |
|
141 |
{ |
|
142 |
mBlurApplied[object] = false; |
|
143 |
mEffects[object].abortEffect(mBlur[object]); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
123 | 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 149 |
|
125 | 150 |
void setTransparency(int object, float level) |
src/main/res/layout/transparencylayout.xml | ||
---|---|---|
30 | 30 |
/> |
31 | 31 |
</LinearLayout> |
32 | 32 |
|
33 |
<SeekBar |
|
34 |
android:id="@+id/transparencySeekRed" |
|
35 |
android:background="@color/red" |
|
36 |
android:layout_height="50dp" |
|
33 |
<LinearLayout |
|
37 | 34 |
android:layout_width="fill_parent" |
38 |
android:paddingLeft="10dp" |
|
39 |
android:paddingRight="10dp" /> |
|
40 |
<SeekBar |
|
41 |
android:id="@+id/transparencySeekYellow" |
|
42 |
android:background="@color/yellow" |
|
43 | 35 |
android:layout_height="50dp" |
36 |
android:orientation="horizontal"> |
|
37 |
|
|
38 |
<CheckBox |
|
39 |
android:layout_height="fill_parent" |
|
40 |
android:layout_width="wrap_content" |
|
41 |
android:background="@color/red" |
|
42 |
android:id="@+id/transparencyCheckBox0" |
|
43 |
android:paddingLeft="10dp" |
|
44 |
android:onClick="onClick" |
|
45 |
android:checked="true"/> |
|
46 |
|
|
47 |
<SeekBar |
|
48 |
android:id="@+id/transparencySeekRed" |
|
49 |
android:background="@color/red" |
|
50 |
android:layout_height="fill_parent" |
|
51 |
android:layout_width="fill_parent" |
|
52 |
android:paddingLeft="10dp" |
|
53 |
android:paddingRight="10dp" /> |
|
54 |
|
|
55 |
</LinearLayout> |
|
56 |
|
|
57 |
<LinearLayout |
|
44 | 58 |
android:layout_width="fill_parent" |
45 |
android:paddingLeft="10dp"
|
|
46 |
android:paddingRight="10dp" />
|
|
59 |
android:layout_height="50dp"
|
|
60 |
android:orientation="horizontal">
|
|
47 | 61 |
|
62 |
<CheckBox |
|
63 |
android:layout_height="fill_parent" |
|
64 |
android:layout_width="wrap_content" |
|
65 |
android:background="@color/yellow" |
|
66 |
android:id="@+id/transparencyCheckBox1" |
|
67 |
android:paddingLeft="10dp" |
|
68 |
android:onClick="onClick" |
|
69 |
android:checked="true"/> |
|
70 |
|
|
71 |
<SeekBar |
|
72 |
android:id="@+id/transparencySeekYellow" |
|
73 |
android:background="@color/yellow" |
|
74 |
android:layout_height="fill_parent" |
|
75 |
android:layout_width="fill_parent" |
|
76 |
android:paddingLeft="10dp" |
|
77 |
android:paddingRight="10dp" /> |
|
78 |
|
|
79 |
</LinearLayout> |
|
48 | 80 |
</LinearLayout> |
Also available in: Unified diff
Transparency App: try to postprocess and not-postprocess the Transparent Surfaces.