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.movingeffects;
|
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.GLES20;
|
30
|
import android.opengl.GLSurfaceView;
|
31
|
|
32
|
import org.distorted.library.DistortedBitmap;
|
33
|
import org.distorted.library.Distorted;
|
34
|
|
35
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36
|
|
37
|
class MovingEffectsRenderer implements GLSurfaceView.Renderer
|
38
|
{
|
39
|
private GLSurfaceView mView;
|
40
|
private Canvas mCanvas;
|
41
|
private Bitmap mBitmap;
|
42
|
private Paint mPaint;
|
43
|
private int texW, texH;
|
44
|
|
45
|
static DistortedBitmap mBackground;
|
46
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
|
49
|
MovingEffectsRenderer(GLSurfaceView v)
|
50
|
{
|
51
|
mPaint = new Paint();
|
52
|
mPaint.setAntiAlias(true);
|
53
|
mPaint.setFakeBoldText(true);
|
54
|
mPaint.setStyle(Style.FILL);
|
55
|
|
56
|
mView = v;
|
57
|
}
|
58
|
|
59
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60
|
|
61
|
private void drawBackground()
|
62
|
{
|
63
|
int NW, NH;
|
64
|
|
65
|
if( texH<texW )
|
66
|
{
|
67
|
NH = 10;
|
68
|
NW = NH*texW/texH;
|
69
|
}
|
70
|
else
|
71
|
{
|
72
|
NW = 10;
|
73
|
NH = NW*texH/texW;
|
74
|
}
|
75
|
|
76
|
mPaint.setColor(0xff008800);
|
77
|
mCanvas.drawRect(0, 0, texW, texH, mPaint);
|
78
|
mPaint.setColor(0xffffffff);
|
79
|
|
80
|
for(int i=0; i<=NH ; i++ ) mCanvas.drawRect( 0, texH*i/NH -2, texW, texH*i/NH + 2, mPaint);
|
81
|
for(int i=0; i<=NW ; i++ ) mCanvas.drawRect( texW*i/NW - 2, 0, texW*i/NW + 2, texH, mPaint);
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
|
86
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
87
|
{
|
88
|
try
|
89
|
{
|
90
|
Distorted.onSurfaceCreated(mView.getContext());
|
91
|
}
|
92
|
catch(Exception ex)
|
93
|
{
|
94
|
android.util.Log.e("Renderer", ex.getMessage() );
|
95
|
}
|
96
|
}
|
97
|
|
98
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
99
|
|
100
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
101
|
{
|
102
|
texW = width;
|
103
|
texH = height;
|
104
|
|
105
|
mBackground = new DistortedBitmap(texW,texH, 80);
|
106
|
mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
|
107
|
mCanvas = new Canvas(mBitmap);
|
108
|
|
109
|
Distorted.onSurfaceChanged(texW, texH);
|
110
|
MovingEffectsSurfaceView.onSurfaceChanged(texW,texH);
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
public void onDrawFrame(GL10 glUnused)
|
116
|
{
|
117
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
|
118
|
|
119
|
long time = System.currentTimeMillis();
|
120
|
|
121
|
if (MovingEffectsSurfaceView.getCurrentEffect() == MovingEffectsSurfaceView.EFFECT_POINTS )
|
122
|
{
|
123
|
drawBackground();
|
124
|
MovingEffectsSurfaceView.drawCurve(mCanvas,time);
|
125
|
mBackground.setBitmap(mBitmap);
|
126
|
}
|
127
|
|
128
|
mBackground.draw(time);
|
129
|
}
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
}
|