Revision f1b8b412
Added by Leszek Koltunski over 6 years ago
src/main/java/org/distorted/examples/triblur/TriblurActivity.java | ||
---|---|---|
35 | 35 |
public class TriblurActivity extends Activity implements SeekBar.OnSeekBarChangeListener |
36 | 36 |
{ |
37 | 37 |
private int mQuality; |
38 |
private int mBackground; |
|
38 | 39 |
|
39 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 41 |
|
... | ... | |
58 | 59 |
radiusBar1.setProgress(50); |
59 | 60 |
radiusBar2.setProgress(70); |
60 | 61 |
|
61 |
mQuality = EffectQuality.HIGH.ordinal(); |
|
62 |
privateQuality(1); |
|
63 |
privateBackgroundColor(1); |
|
62 | 64 |
} |
63 | 65 |
} |
64 | 66 |
|
... | ... | |
104 | 106 |
|
105 | 107 |
savedInstanceState.putBooleanArray("checkboxes", renderer.getChecked() ); |
106 | 108 |
savedInstanceState.putInt("quality", mQuality); |
109 |
savedInstanceState.putInt("background", mBackground); |
|
107 | 110 |
} |
108 | 111 |
|
109 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
126 | 129 |
} |
127 | 130 |
} |
128 | 131 |
|
129 |
mQuality = savedInstanceState.getInt("quality"); |
|
132 |
mQuality = savedInstanceState.getInt("quality"); |
|
133 |
mBackground = savedInstanceState.getInt("background"); |
|
130 | 134 |
|
131 |
switch(mQuality) |
|
132 |
{ |
|
133 |
case 0 : quality0(null); break; |
|
134 |
case 1 : quality1(null); break; |
|
135 |
case 2 : quality2(null); break; |
|
136 |
case 3 : quality3(null); break; |
|
137 |
default: android.util.Log.e("TriBlur", "error - unknown quality!"); |
|
138 |
} |
|
135 |
privateQuality(mQuality); |
|
136 |
privateBackgroundColor(mBackground); |
|
139 | 137 |
} |
140 | 138 |
|
141 | 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
169 | 167 |
public void onClick(View view) |
170 | 168 |
{ |
171 | 169 |
CheckBox box = (CheckBox)view; |
172 |
int id = box.getId(); |
|
173 | 170 |
boolean checked = box.isChecked(); |
174 | 171 |
TriblurSurfaceView sView = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView); |
175 | 172 |
|
176 |
switch(id)
|
|
173 |
switch(box.getId())
|
|
177 | 174 |
{ |
178 | 175 |
case R.id.triblurCheckBox0 : sView.getRenderer().setChecked(0,checked); break; |
179 | 176 |
case R.id.triblurCheckBox1 : sView.getRenderer().setChecked(1,checked); break; |
... | ... | |
183 | 180 |
|
184 | 181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
185 | 182 |
|
186 |
public void quality0(View v)
|
|
183 |
public void backgroundColor(View v)
|
|
187 | 184 |
{ |
188 |
TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView); |
|
189 |
TriblurRenderer renderer = view.getRenderer(); |
|
190 |
renderer.setQuality(EffectQuality.HIGHEST); |
|
191 |
mQuality = EffectQuality.HIGHEST.ordinal(); |
|
185 |
switch(v.getId()) |
|
186 |
{ |
|
187 |
case R.id.triblurRadioBackground0: privateBackgroundColor(0); break; |
|
188 |
case R.id.triblurRadioBackground1: privateBackgroundColor(1); break; |
|
189 |
case R.id.triblurRadioBackground2: privateBackgroundColor(2); break; |
|
190 |
} |
|
192 | 191 |
} |
193 | 192 |
|
194 | 193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
195 | 194 |
|
196 |
public void quality1(View v)
|
|
195 |
public void quality(View v) |
|
197 | 196 |
{ |
198 |
TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView); |
|
199 |
TriblurRenderer renderer = view.getRenderer(); |
|
200 |
renderer.setQuality(EffectQuality.HIGH); |
|
201 |
mQuality = EffectQuality.HIGH.ordinal(); |
|
197 |
switch(v.getId()) |
|
198 |
{ |
|
199 |
case R.id.triblurRadioQuality0: privateQuality(0); break; |
|
200 |
case R.id.triblurRadioQuality1: privateQuality(1); break; |
|
201 |
case R.id.triblurRadioQuality2: privateQuality(2); break; |
|
202 |
case R.id.triblurRadioQuality3: privateQuality(3); break; |
|
203 |
} |
|
202 | 204 |
} |
203 | 205 |
|
204 | 206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
205 | 207 |
|
206 |
public void quality2(View v)
|
|
208 |
private void privateBackgroundColor(int index)
|
|
207 | 209 |
{ |
208 | 210 |
TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView); |
209 | 211 |
TriblurRenderer renderer = view.getRenderer(); |
210 |
renderer.setQuality(EffectQuality.MEDIUM); |
|
211 |
mQuality = EffectQuality.MEDIUM.ordinal(); |
|
212 |
|
|
213 |
switch(index) |
|
214 |
{ |
|
215 |
case 0: renderer.setBackground(0.0f,0.0f,0.0f,1.0f); mBackground=0; break; |
|
216 |
case 1: renderer.setBackground(1.0f,1.0f,1.0f,1.0f); mBackground=1; break; |
|
217 |
case 2: renderer.setBackground(0.0f,0.0f,1.0f,1.0f); mBackground=2; break; |
|
218 |
} |
|
212 | 219 |
} |
213 | 220 |
|
214 | 221 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
215 | 222 |
|
216 |
public void quality3(View v)
|
|
223 |
private void privateQuality(int index)
|
|
217 | 224 |
{ |
218 | 225 |
TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView); |
219 | 226 |
TriblurRenderer renderer = view.getRenderer(); |
220 |
renderer.setQuality(EffectQuality.LOW); |
|
221 |
mQuality = EffectQuality.LOW.ordinal(); |
|
227 |
|
|
228 |
switch(index) |
|
229 |
{ |
|
230 |
case 0: renderer.setQuality(EffectQuality.HIGHEST); |
|
231 |
mQuality = EffectQuality.HIGHEST.ordinal(); |
|
232 |
break; |
|
233 |
case 1: renderer.setQuality(EffectQuality.HIGH); |
|
234 |
mQuality = EffectQuality.HIGH.ordinal(); |
|
235 |
break; |
|
236 |
case 2: renderer.setQuality(EffectQuality.MEDIUM); |
|
237 |
mQuality = EffectQuality.MEDIUM.ordinal(); |
|
238 |
break; |
|
239 |
case 3: renderer.setQuality(EffectQuality.LOW); |
|
240 |
mQuality = EffectQuality.LOW.ordinal(); |
|
241 |
break; |
|
222 | 242 |
} |
243 |
} |
|
223 | 244 |
} |
src/main/java/org/distorted/examples/triblur/TriblurRenderer.java | ||
---|---|---|
50 | 50 |
|
51 | 51 |
class TriblurRenderer implements GLSurfaceView.Renderer |
52 | 52 |
{ |
53 |
private static final int NUM = 6; // 6 ints (x,y,z,R,G,B) each describe 1 object below |
|
54 |
|
|
53 | 55 |
private static final int[] OBJECTS = |
54 | 56 |
{ |
55 | 57 |
-1, 0, 0, 255, 0, 0, // x,y,z, R,G,B |
... | ... | |
57 | 59 |
+1, 0, 0, 0, 255, 0, // |
58 | 60 |
}; |
59 | 61 |
|
60 |
private static final int NUM_OBJECTS = OBJECTS.length/6;
|
|
62 |
private static final int NUM_OBJECTS = OBJECTS.length/NUM;
|
|
61 | 63 |
private static final int OBJ_SIZE = 100; |
62 | 64 |
|
63 | 65 |
private GLSurfaceView mView; |
... | ... | |
115 | 117 |
for(int i=0; i<NUM_OBJECTS; i++) |
116 | 118 |
{ |
117 | 119 |
mMoveVector[i] = new Static3D(0,0,0); |
118 |
mChromaVector[i] = new Static3D(OBJECTS[6*i+3],OBJECTS[6*i+4],OBJECTS[6*i+5]);
|
|
120 |
mChromaVector[i] = new Static3D(OBJECTS[NUM*i+3],OBJECTS[NUM*i+4],OBJECTS[NUM*i+5]);
|
|
119 | 121 |
mBlurVector[i] = new Static1D(10); |
120 | 122 |
mBlur[i] = new PostprocessEffectBlur(mBlurVector[i]); |
121 | 123 |
mChroma[i] = new FragmentEffectChroma( new Static1D(0.3f), mChromaVector[i]); |
... | ... | |
147 | 149 |
} |
148 | 150 |
} |
149 | 151 |
|
152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
153 |
|
|
154 |
void setBackground(float r, float g, float b, float a) |
|
155 |
{ |
|
156 |
mScreen.glClearColor(r,g,b,a); |
|
157 |
} |
|
158 |
|
|
150 | 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
151 | 160 |
|
152 | 161 |
public void onDrawFrame(GL10 glUnused) |
... | ... | |
211 | 220 |
|
212 | 221 |
for(int i=0; i<NUM_OBJECTS; i++) |
213 | 222 |
{ |
214 |
mMoveVector[i].set(size*OBJECTS[6*i], size*OBJECTS[6*i+1], size*OBJECTS[6*i+2]);
|
|
223 |
mMoveVector[i].set(size*OBJECTS[NUM*i], size*OBJECTS[NUM*i+1], size*OBJECTS[NUM*i+2]);
|
|
215 | 224 |
} |
216 | 225 |
} |
217 | 226 |
|
src/main/res/layout/triblurlayout.xml | ||
---|---|---|
82 | 82 |
android:paddingRight="10dp" /> |
83 | 83 |
</LinearLayout> |
84 | 84 |
|
85 |
<LinearLayout |
|
86 |
android:id="@+id/linearLayout2" |
|
87 |
android:layout_width="fill_parent" |
|
88 |
android:layout_height="wrap_content" |
|
89 |
android:gravity="center|fill_horizontal" |
|
90 |
android:orientation="horizontal" |
|
91 |
android:background="@color/cyan" |
|
92 |
android:paddingBottom="10dp" |
|
93 |
android:paddingTop="10dp" > |
|
94 |
|
|
95 |
<RadioGroup |
|
96 |
android:id="@+id/triblurRadioBackground" |
|
97 |
android:layout_width="match_parent" |
|
98 |
android:layout_height="wrap_content" |
|
99 |
android:orientation="horizontal"> |
|
100 |
|
|
101 |
<RadioButton |
|
102 |
android:id="@+id/triblurRadioBackground0" |
|
103 |
android:layout_width="match_parent" |
|
104 |
android:layout_height="wrap_content" |
|
105 |
android:layout_weight="1" |
|
106 |
android:onClick="backgroundColor" |
|
107 |
android:text="@string/color_black" |
|
108 |
android:textSize="16sp"/> |
|
109 |
|
|
110 |
<RadioButton |
|
111 |
android:id="@+id/triblurRadioBackground1" |
|
112 |
android:layout_width="match_parent" |
|
113 |
android:layout_height="wrap_content" |
|
114 |
android:layout_weight="1" |
|
115 |
android:checked="true" |
|
116 |
android:onClick="backgroundColor" |
|
117 |
android:text="@string/color_white" |
|
118 |
android:textSize="16sp"/> |
|
119 |
|
|
120 |
<RadioButton |
|
121 |
android:id="@+id/triblurRadioBackground2" |
|
122 |
android:layout_width="match_parent" |
|
123 |
android:layout_height="wrap_content" |
|
124 |
android:layout_weight="1" |
|
125 |
android:onClick="backgroundColor" |
|
126 |
android:text="@string/color_blue" |
|
127 |
android:textSize="16sp"/> |
|
128 |
|
|
129 |
</RadioGroup> |
|
130 |
|
|
131 |
</LinearLayout> |
|
132 |
|
|
85 | 133 |
<LinearLayout |
86 | 134 |
android:id="@+id/linearLayout3" |
87 | 135 |
android:layout_width="fill_parent" |
... | ... | |
103 | 151 |
android:layout_width="match_parent" |
104 | 152 |
android:layout_height="wrap_content" |
105 | 153 |
android:layout_weight="1" |
106 |
android:onClick="quality0"
|
|
154 |
android:onClick="quality" |
|
107 | 155 |
android:text="@string/quality0" |
108 | 156 |
android:textSize="14sp"/> |
109 | 157 |
|
... | ... | |
113 | 161 |
android:layout_height="wrap_content" |
114 | 162 |
android:layout_weight="1" |
115 | 163 |
android:checked="true" |
116 |
android:onClick="quality1"
|
|
164 |
android:onClick="quality" |
|
117 | 165 |
android:text="@string/quality1" |
118 | 166 |
android:textSize="14sp"/> |
119 | 167 |
|
... | ... | |
122 | 170 |
android:layout_width="match_parent" |
123 | 171 |
android:layout_height="wrap_content" |
124 | 172 |
android:layout_weight="1" |
125 |
android:onClick="quality2"
|
|
173 |
android:onClick="quality" |
|
126 | 174 |
android:text="@string/quality2" |
127 | 175 |
android:textSize="14sp"/> |
128 | 176 |
|
... | ... | |
131 | 179 |
android:layout_width="match_parent" |
132 | 180 |
android:layout_height="wrap_content" |
133 | 181 |
android:layout_weight="1" |
134 |
android:onClick="quality3"
|
|
182 |
android:onClick="quality" |
|
135 | 183 |
android:text="@string/quality3" |
136 | 184 |
android:textSize="14sp"/> |
137 | 185 |
|
src/main/res/values/colors.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
2 | 2 |
<resources> |
3 |
<color name="blue">#ff0000ff</color> |
|
4 |
<color name="black">#ff000000</color> |
|
5 |
<color name="red">#ffff0000</color> |
|
6 |
<color name="yellow">#ffffff00</color> |
|
7 |
<color name="green">#ff00ff00</color> |
|
3 |
<color name="blue">#ff0000ff</color> |
|
4 |
<color name="black">#ff000000</color> |
|
5 |
<color name="red">#ffff0000</color> |
|
6 |
<color name="yellow">#ffffff00</color> |
|
7 |
<color name="green">#ff00ff00</color> |
|
8 |
<color name="cyan">#ff00ffff</color> |
|
9 |
<color name="white">#ffffffff</color> |
|
8 | 10 |
</resources> |
src/main/res/values/strings.xml | ||
---|---|---|
73 | 73 |
<string name="screen">Screen</string> |
74 | 74 |
<string name="framebuffer">Framebuffer</string> |
75 | 75 |
|
76 |
<string name="color_blue">Blue</string> |
|
77 |
<string name="color_black">Black</string> |
|
78 |
<string name="color_red">Red</string> |
|
79 |
<string name="color_yellow">Yellow</string> |
|
80 |
<string name="color_green">Green</string> |
|
81 |
<string name="color_cyan">Cyan</string> |
|
82 |
<string name="color_white">White</string> |
|
83 |
|
|
76 | 84 |
<string name="radius_placeholder">Radius: %1$s</string> |
77 | 85 |
<string name="noise_placeholder">Noise %1$s</string> |
78 | 86 |
<string name="length_placeholder">Length %1$d</string> |
Also available in: Unified diff
Improve the Triblur app.