Revision 24ab1cf8
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
---|---|---|
46 | 46 |
{ |
47 | 47 |
private static final int NUM_VECTORS = 8; |
48 | 48 |
private static final int NUM_LINES = 10; |
49 |
private static final int NUM_FRAMES = 100; |
|
50 | 49 |
|
51 | 50 |
private GLSurfaceView mView; |
52 | 51 |
private DistortedTexture stretchTexture; |
... | ... | |
72 | 71 |
private EffectNames mMode = EffectNames.DISTORT; |
73 | 72 |
private long mLastEffect = -1; |
74 | 73 |
|
75 |
// FPS |
|
76 |
private MeshObject fpsMesh; |
|
77 |
private DistortedTexture fpsTexture; |
|
78 |
private DistortedEffects fpsEffects; |
|
79 |
private Canvas fpsCanvas; |
|
80 |
private Bitmap fpsBitmap; |
|
81 |
private Paint mPaint; |
|
82 |
private int fpsH, fpsW; |
|
83 |
private String fpsString = ""; |
|
84 |
private long lastTime=0; |
|
85 |
private long[] durations; |
|
86 |
private int currDuration; |
|
87 |
|
|
88 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
89 | 75 |
|
90 | 76 |
DeformRenderer(GLSurfaceView view) |
91 | 77 |
{ |
92 | 78 |
mView = view; |
93 | 79 |
|
94 |
fpsW = 120; |
|
95 |
fpsH = 70; |
|
96 |
|
|
97 |
fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888); |
|
98 |
fpsMesh = new MeshFlat(1,1); |
|
99 |
fpsTexture = new DistortedTexture(fpsW,fpsH); |
|
100 |
fpsTexture.setTexture(fpsBitmap); |
|
101 |
fpsCanvas = new Canvas(fpsBitmap); |
|
102 |
fpsEffects = new DistortedEffects(); |
|
103 |
fpsEffects.move( new Static3D(5,5,0) ); |
|
104 |
|
|
105 |
mPaint = new Paint(); |
|
106 |
mPaint.setAntiAlias(true); |
|
107 |
mPaint.setTextAlign(Paint.Align.CENTER); |
|
108 |
mPaint.setTextSize(0.7f*fpsH); |
|
109 |
|
|
110 | 80 |
stretchEffects = new DistortedEffects(); |
111 |
|
|
112 | 81 |
mRegion = new Static4D(0,0,0,0); |
113 | 82 |
|
114 |
durations = new long[NUM_FRAMES+1]; |
|
115 |
currDuration = 0; |
|
116 |
|
|
117 |
for(int i=0; i<NUM_FRAMES+1; i++) durations[i]=0; |
|
118 |
|
|
119 | 83 |
// DISTORT |
120 | 84 |
mReleasedDistortDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f); |
121 | 85 |
mReleasedDistortDynamic.setMode(Dynamic3D.MODE_PATH); |
... | ... | |
165 | 129 |
mMovingShearDynamic.add(vShear[0]); |
166 | 130 |
|
167 | 131 |
mScreen = new DistortedScreen(mView); |
132 |
Distorted.setDebug(Distorted.DEBUG_FPS); |
|
168 | 133 |
} |
169 | 134 |
|
170 | 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
186 | 151 |
|
187 | 152 |
public void onDrawFrame(GL10 glUnused) |
188 | 153 |
{ |
189 |
mPaint.setColor(0xffffffff); |
|
190 |
fpsCanvas.drawRect(0, 0, fpsW, fpsH, mPaint); |
|
191 |
mPaint.setColor(0xff000000); |
|
192 |
fpsCanvas.drawText(fpsString, fpsW/2, 0.75f*fpsH, mPaint); |
|
193 |
fpsTexture.setTexture(fpsBitmap); |
|
194 |
|
|
195 |
long time = System.currentTimeMillis(); |
|
196 |
|
|
197 |
mScreen.render(time); |
|
198 |
computeFPS(time); |
|
154 |
mScreen.render(System.currentTimeMillis()); |
|
199 | 155 |
} |
200 | 156 |
|
201 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
217 | 173 |
Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888); |
218 | 174 |
stretchCanvas = new Canvas(stretchBitmap); |
219 | 175 |
|
220 |
mPaint.setColor(0xff008800); |
|
221 |
mPaint.setStyle(Style.FILL); |
|
222 |
stretchCanvas.drawRect(0, 0, w, h, mPaint); |
|
223 |
mPaint.setColor(0xffffffff); |
|
176 |
Paint paint = new Paint(); |
|
177 |
paint.setColor(0xff008800); |
|
178 |
paint.setStyle(Style.FILL); |
|
179 |
stretchCanvas.drawRect(0, 0, w, h, paint); |
|
180 |
paint.setColor(0xffffffff); |
|
224 | 181 |
|
225 | 182 |
for(int i=0; i<=NUM_LINES ; i++ ) |
226 | 183 |
{ |
227 |
stretchCanvas.drawRect(w*i/NUM_LINES - 1, 0, w*i/NUM_LINES + 1, h , mPaint);
|
|
228 |
stretchCanvas.drawRect( 0, h *i/NUM_LINES -1, w , h*i/NUM_LINES + 1, mPaint);
|
|
184 |
stretchCanvas.drawRect(w*i/NUM_LINES - 1, 0, w*i/NUM_LINES + 1, h , paint);
|
|
185 |
stretchCanvas.drawRect( 0, h *i/NUM_LINES -1, w , h*i/NUM_LINES + 1, paint);
|
|
229 | 186 |
} |
230 | 187 |
|
231 | 188 |
touchPoint= new Static3D(0,0,0); |
... | ... | |
238 | 195 |
|
239 | 196 |
mScreen.detachAll(); |
240 | 197 |
mScreen.attach(stretchTexture,stretchEffects,stretchMesh); |
241 |
mScreen.attach(fpsTexture,fpsEffects,fpsMesh); |
|
242 | 198 |
|
243 | 199 |
mScreen.resize(width, height); |
244 | 200 |
} |
... | ... | |
336 | 292 |
break; |
337 | 293 |
} |
338 | 294 |
} |
339 |
|
|
340 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
341 |
|
|
342 |
private void computeFPS(long currentTime) |
|
343 |
{ |
|
344 |
if( lastTime!=0 ) |
|
345 |
{ |
|
346 |
currDuration++; |
|
347 |
if( currDuration>=NUM_FRAMES ) currDuration = 0; |
|
348 |
durations[NUM_FRAMES] += ((currentTime-lastTime)-durations[currDuration]); |
|
349 |
durations[currDuration] = currentTime-lastTime; |
|
350 |
|
|
351 |
fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f; |
|
352 |
} |
|
353 |
|
|
354 |
lastTime = currentTime; |
|
355 |
} |
|
356 | 295 |
} |
Also available in: Unified diff
Move showing FPS in the uppoer-left corner of the Screen to the Library.
App can enable/disable this at any time with a single API call.