1 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
e3900503
|
Leszek Koltunski
|
// This file is part of DistortedLibrary. //
|
5 |
bc0a685b
|
Leszek Koltunski
|
// //
|
6 |
e3900503
|
Leszek Koltunski
|
// DistortedLibrary is free software: you can redistribute it and/or modify //
|
7 |
bc0a685b
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
e3900503
|
Leszek Koltunski
|
// DistortedLibrary is distributed in the hope that it will be useful, //
|
12 |
bc0a685b
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
e3900503
|
Leszek Koltunski
|
// along with DistortedLibrary. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
f988589e
|
Leszek Koltunski
|
package org.distorted.examples.dynamic;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
22 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
23 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
24 |
|
|
|
25 |
|
|
import android.graphics.Bitmap;
|
26 |
|
|
import android.graphics.Canvas;
|
27 |
|
|
import android.graphics.Paint;
|
28 |
|
|
import android.graphics.Paint.Style;
|
29 |
|
|
import android.opengl.GLSurfaceView;
|
30 |
|
|
|
31 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
32 |
|
|
import org.distorted.library.main.DistortedScreen;
|
33 |
107e4b72
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshFlat;
|
34 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedTexture;
|
35 |
e3900503
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
36 |
427ab7bf
|
Leszek Koltunski
|
|
37 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38 |
|
|
|
39 |
97dadfe5
|
Leszek Koltunski
|
class DynamicRenderer implements GLSurfaceView.Renderer
|
40 |
427ab7bf
|
Leszek Koltunski
|
{
|
41 |
fe3c72ce
|
Leszek Koltunski
|
private DynamicSurfaceView mView;
|
42 |
40eef4b9
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
43 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
44 |
d218d64e
|
leszek
|
private DistortedScreen mScreen;
|
45 |
b01acdaf
|
Leszek Koltunski
|
private MeshFlat mMesh;
|
46 |
427ab7bf
|
Leszek Koltunski
|
private Canvas mCanvas;
|
47 |
|
|
private Bitmap mBitmap;
|
48 |
|
|
private Paint mPaint;
|
49 |
97dadfe5
|
Leszek Koltunski
|
|
50 |
|
|
static int texW, texH;
|
51 |
427ab7bf
|
Leszek Koltunski
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
fe3c72ce
|
Leszek Koltunski
|
DynamicRenderer(DynamicSurfaceView v)
|
55 |
427ab7bf
|
Leszek Koltunski
|
{
|
56 |
|
|
mPaint = new Paint();
|
57 |
|
|
mPaint.setAntiAlias(true);
|
58 |
|
|
mPaint.setFakeBoldText(true);
|
59 |
|
|
mPaint.setColor(0xff447da7);
|
60 |
|
|
mPaint.setStyle(Style.FILL);
|
61 |
|
|
|
62 |
fe59d375
|
Leszek Koltunski
|
mView = v;
|
63 |
|
|
mMesh = new MeshFlat(1,1);
|
64 |
d04a4886
|
Leszek Koltunski
|
mEffects = new DistortedEffects();
|
65 |
e4330c89
|
Leszek Koltunski
|
mScreen = new DistortedScreen();
|
66 |
427ab7bf
|
Leszek Koltunski
|
}
|
67 |
|
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
71 |
|
|
{
|
72 |
|
|
try
|
73 |
3c8b1903
|
Leszek Koltunski
|
{
|
74 |
e3900503
|
Leszek Koltunski
|
DistortedLibrary.onCreate(mView.getContext());
|
75 |
3c8b1903
|
Leszek Koltunski
|
}
|
76 |
|
|
catch(Exception ex)
|
77 |
|
|
{
|
78 |
|
|
android.util.Log.e("Renderer", ex.getMessage() );
|
79 |
|
|
}
|
80 |
427ab7bf
|
Leszek Koltunski
|
}
|
81 |
|
|
|
82 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83 |
|
|
|
84 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
85 |
|
|
{
|
86 |
97dadfe5
|
Leszek Koltunski
|
texW = width;
|
87 |
|
|
texH = height;
|
88 |
|
|
|
89 |
b0ebdf5e
|
Leszek Koltunski
|
if( mTexture!=null ) mTexture.markForDeletion();
|
90 |
7451c98a
|
Leszek Koltunski
|
mTexture= new DistortedTexture(texW,texH);
|
91 |
40eef4b9
|
Leszek Koltunski
|
mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
|
92 |
|
|
mCanvas = new Canvas(mBitmap);
|
93 |
97dadfe5
|
Leszek Koltunski
|
|
94 |
fe59d375
|
Leszek Koltunski
|
mScreen.detachAll();
|
95 |
|
|
mScreen.attach(mTexture,mEffects,mMesh);
|
96 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(texW,texH);
|
97 |
fe3c72ce
|
Leszek Koltunski
|
mView.onSurfaceChanged(texW,texH);
|
98 |
427ab7bf
|
Leszek Koltunski
|
}
|
99 |
|
|
|
100 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101 |
|
|
|
102 |
|
|
public void onDrawFrame(GL10 glUnused)
|
103 |
|
|
{
|
104 |
|
|
long time = System.currentTimeMillis();
|
105 |
|
|
|
106 |
97dadfe5
|
Leszek Koltunski
|
mCanvas.drawRect(0, 0, texW, texH, mPaint);
|
107 |
fe3c72ce
|
Leszek Koltunski
|
mView.drawCurve(mCanvas,time);
|
108 |
40eef4b9
|
Leszek Koltunski
|
mTexture.setTexture(mBitmap);
|
109 |
fe59d375
|
Leszek Koltunski
|
mScreen.render( System.currentTimeMillis() );
|
110 |
427ab7bf
|
Leszek Koltunski
|
}
|
111 |
|
|
|
112 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
|
}
|