1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// Distorted is free software: you can redistribute it and/or modify //
|
7
|
// 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
|
// Distorted is distributed in the hope that it will be useful, //
|
12
|
// 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
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.examples.dynamic;
|
21
|
|
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
|
import org.distorted.library.main.DistortedEffects;
|
32
|
import org.distorted.library.main.DistortedScreen;
|
33
|
import org.distorted.library.main.MeshFlat;
|
34
|
import org.distorted.library.main.DistortedTexture;
|
35
|
import org.distorted.library.main.Distorted;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
class DynamicRenderer implements GLSurfaceView.Renderer
|
40
|
{
|
41
|
private DynamicSurfaceView mView;
|
42
|
private DistortedTexture mTexture;
|
43
|
private DistortedEffects mEffects;
|
44
|
private DistortedScreen mScreen;
|
45
|
private MeshFlat mMesh;
|
46
|
private Canvas mCanvas;
|
47
|
private Bitmap mBitmap;
|
48
|
private Paint mPaint;
|
49
|
|
50
|
static int texW, texH;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
DynamicRenderer(DynamicSurfaceView v)
|
55
|
{
|
56
|
mPaint = new Paint();
|
57
|
mPaint.setAntiAlias(true);
|
58
|
mPaint.setFakeBoldText(true);
|
59
|
mPaint.setColor(0xff447da7);
|
60
|
mPaint.setStyle(Style.FILL);
|
61
|
|
62
|
mView = v;
|
63
|
mMesh = new MeshFlat(1,1);
|
64
|
mEffects = new DistortedEffects();
|
65
|
mScreen = new DistortedScreen();
|
66
|
}
|
67
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
|
70
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
71
|
{
|
72
|
try
|
73
|
{
|
74
|
Distorted.onCreate(mView.getContext());
|
75
|
}
|
76
|
catch(Exception ex)
|
77
|
{
|
78
|
android.util.Log.e("Renderer", ex.getMessage() );
|
79
|
}
|
80
|
}
|
81
|
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
|
84
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
85
|
{
|
86
|
texW = width;
|
87
|
texH = height;
|
88
|
|
89
|
if( mTexture!=null ) mTexture.markForDeletion();
|
90
|
mTexture= new DistortedTexture(texW,texH);
|
91
|
mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
|
92
|
mCanvas = new Canvas(mBitmap);
|
93
|
|
94
|
mScreen.detachAll();
|
95
|
mScreen.attach(mTexture,mEffects,mMesh);
|
96
|
mScreen.resize(texW,texH);
|
97
|
mView.onSurfaceChanged(texW,texH);
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
public void onDrawFrame(GL10 glUnused)
|
103
|
{
|
104
|
long time = System.currentTimeMillis();
|
105
|
|
106
|
mCanvas.drawRect(0, 0, texW, texH, mPaint);
|
107
|
mView.drawCurve(mCanvas,time);
|
108
|
mTexture.setTexture(mBitmap);
|
109
|
mScreen.render( System.currentTimeMillis() );
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
}
|