Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/movingglow/MovingGlowRenderer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.movingglow; |
21 | 21 |
|
22 |
import android.app.ActivityManager; |
|
23 |
import android.content.Context; |
|
24 |
import android.content.pm.ConfigurationInfo; |
|
25 |
import android.content.res.Resources; |
|
22 | 26 |
import android.graphics.Bitmap; |
23 | 27 |
import android.graphics.BitmapFactory; |
24 | 28 |
import android.opengl.GLSurfaceView; |
... | ... | |
52 | 56 |
|
53 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 58 |
|
55 |
class MovingGlowRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.ExceptionListener
|
|
59 |
class MovingGlowRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.LibraryUser
|
|
56 | 60 |
{ |
57 | 61 |
private static final int[] colors = new int[] {0,0,1, 1,0,1, 1,0,0, 1,1,0, 0,1,0, 1,1,1}; // blue, pink, red, yellow, green, white |
58 | 62 |
private static final int FLASH_TIME = 2000; |
59 | 63 |
private static final int LEAF_SIZE = 100; |
60 | 64 |
private static final int NUM_LEAVES= colors.length/3; |
61 | 65 |
|
62 |
private GLSurfaceView mView; |
|
63 |
private DistortedTexture mLeaf; |
|
64 |
private DistortedScreen mScreen; |
|
65 |
private DistortedEffects[] mLeafEffects = new DistortedEffects[NUM_LEAVES]; |
|
66 |
private PostprocessEffectGlow[] mGlow = new PostprocessEffectGlow[NUM_LEAVES]; |
|
66 |
private final GLSurfaceView mView; |
|
67 |
private final Resources mResources; |
|
68 |
private final DistortedTexture mLeaf; |
|
69 |
private final DistortedScreen mScreen; |
|
70 |
private final DistortedEffects[] mLeafEffects = new DistortedEffects[NUM_LEAVES]; |
|
71 |
private final PostprocessEffectGlow[] mGlow = new PostprocessEffectGlow[NUM_LEAVES]; |
|
72 |
private final Static3D mScale; |
|
73 |
private final Dynamic2D mHaloAndRadiusDyn; |
|
74 |
private final Dynamic4D[] mColorDyn; |
|
75 |
|
|
67 | 76 |
private int mGlowing; |
68 |
private Static3D mScale; |
|
69 |
private Dynamic2D mHaloAndRadiusDyn; |
|
70 |
private Dynamic4D[] mColorDyn; |
|
71 | 77 |
|
72 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 | 79 |
|
74 | 80 |
MovingGlowRenderer(GLSurfaceView v) |
75 | 81 |
{ |
76 | 82 |
mView = v; |
83 |
mResources = v.getResources(); |
|
77 | 84 |
|
78 | 85 |
MeshQuad mesh = new MeshQuad(); |
79 | 86 |
mesh.setComponentCenter(0,0,0,-0.1f); |
... | ... | |
194 | 201 |
{ |
195 | 202 |
is.close(); |
196 | 203 |
} |
197 |
catch(IOException e) { }
|
|
204 |
catch(IOException ignored) { }
|
|
198 | 205 |
} |
199 | 206 |
|
200 | 207 |
mLeaf.setTexture(leaf); |
... | ... | |
202 | 209 |
FragmentEffectChroma.enable(); |
203 | 210 |
PostprocessEffectGlow.enable(); |
204 | 211 |
|
205 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
|
|
212 |
DistortedLibrary.onSurfaceCreated(this); |
|
206 | 213 |
} |
207 | 214 |
|
208 | 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
211 | 218 |
{ |
212 | 219 |
android.util.Log.e("MovingGlow", ex.getMessage() ); |
213 | 220 |
} |
221 |
|
|
222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
223 |
|
|
224 |
public int openGlVersion() |
|
225 |
{ |
|
226 |
Context context = mView.getContext(); |
|
227 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
228 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
229 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
230 |
int major = glESversion >> 16; |
|
231 |
int minor = glESversion & 0xff; |
|
232 |
|
|
233 |
return 100*major + 10*minor; |
|
234 |
} |
|
235 |
|
|
236 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
237 |
|
|
238 |
public InputStream localFile(int fileID) |
|
239 |
{ |
|
240 |
return mResources.openRawResource(fileID); |
|
241 |
} |
|
242 |
|
|
243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
244 |
|
|
245 |
public void logMessage(String message) |
|
246 |
{ |
|
247 |
android.util.Log.e("MovingGlow", message ); |
|
248 |
} |
|
214 | 249 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.