1 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.movingeffects;
|
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 |
41a81a14
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
30 |
427ab7bf
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
31 |
|
|
|
32 |
d218d64e
|
leszek
|
import org.distorted.library.DistortedScreen;
|
33 |
f6d884d5
|
Leszek Koltunski
|
import org.distorted.library.DistortedTexture;
|
34 |
d04a4886
|
Leszek Koltunski
|
import org.distorted.library.DistortedEffects;
|
35 |
6637d0f2
|
Leszek Koltunski
|
import org.distorted.library.EffectNames;
|
36 |
b01acdaf
|
Leszek Koltunski
|
import org.distorted.library.MeshFlat;
|
37 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
38 |
427ab7bf
|
Leszek Koltunski
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
97dadfe5
|
Leszek Koltunski
|
class MovingEffectsRenderer implements GLSurfaceView.Renderer
|
42 |
427ab7bf
|
Leszek Koltunski
|
{
|
43 |
4562f295
|
Leszek Koltunski
|
private MovingEffectsSurfaceView mView;
|
44 |
427ab7bf
|
Leszek Koltunski
|
private Canvas mCanvas;
|
45 |
|
|
private Bitmap mBitmap;
|
46 |
|
|
private Paint mPaint;
|
47 |
97dadfe5
|
Leszek Koltunski
|
private int texW, texH;
|
48 |
|
|
|
49 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
50 |
f6d884d5
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
51 |
d218d64e
|
leszek
|
private DistortedScreen mScreen;
|
52 |
3c8b1903
|
Leszek Koltunski
|
private boolean mRefresh;
|
53 |
97dadfe5
|
Leszek Koltunski
|
|
54 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
4562f295
|
Leszek Koltunski
|
MovingEffectsRenderer(MovingEffectsSurfaceView v)
|
57 |
427ab7bf
|
Leszek Koltunski
|
{
|
58 |
|
|
mPaint = new Paint();
|
59 |
|
|
mPaint.setAntiAlias(true);
|
60 |
|
|
mPaint.setFakeBoldText(true);
|
61 |
|
|
mPaint.setStyle(Style.FILL);
|
62 |
f6d884d5
|
Leszek Koltunski
|
|
63 |
392e16fd
|
Leszek Koltunski
|
mView = v;
|
64 |
d04a4886
|
Leszek Koltunski
|
mEffects= new DistortedEffects();
|
65 |
d218d64e
|
leszek
|
mScreen = new DistortedScreen();
|
66 |
392e16fd
|
Leszek Koltunski
|
mRefresh= true;
|
67 |
427ab7bf
|
Leszek Koltunski
|
}
|
68 |
|
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
private void drawBackground()
|
72 |
|
|
{
|
73 |
97dadfe5
|
Leszek Koltunski
|
int NW, NH;
|
74 |
|
|
|
75 |
|
|
if( texH<texW )
|
76 |
|
|
{
|
77 |
|
|
NH = 10;
|
78 |
|
|
NW = NH*texW/texH;
|
79 |
|
|
}
|
80 |
|
|
else
|
81 |
|
|
{
|
82 |
|
|
NW = 10;
|
83 |
|
|
NH = NW*texH/texW;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
427ab7bf
|
Leszek Koltunski
|
mPaint.setColor(0xff008800);
|
87 |
97dadfe5
|
Leszek Koltunski
|
mCanvas.drawRect(0, 0, texW, texH, mPaint);
|
88 |
427ab7bf
|
Leszek Koltunski
|
mPaint.setColor(0xffffffff);
|
89 |
|
|
|
90 |
97dadfe5
|
Leszek Koltunski
|
for(int i=0; i<=NH ; i++ ) mCanvas.drawRect( 0, texH*i/NH -2, texW, texH*i/NH + 2, mPaint);
|
91 |
|
|
for(int i=0; i<=NW ; i++ ) mCanvas.drawRect( texW*i/NW - 2, 0, texW*i/NW + 2, texH, mPaint);
|
92 |
427ab7bf
|
Leszek Koltunski
|
}
|
93 |
|
|
|
94 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95 |
f6d884d5
|
Leszek Koltunski
|
|
96 |
d04a4886
|
Leszek Koltunski
|
DistortedEffects getEffects()
|
97 |
f6d884d5
|
Leszek Koltunski
|
{
|
98 |
392e16fd
|
Leszek Koltunski
|
return mEffects;
|
99 |
f6d884d5
|
Leszek Koltunski
|
}
|
100 |
|
|
|
101 |
3c8b1903
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
void setRefresh()
|
104 |
|
|
{
|
105 |
|
|
mRefresh = true;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
f6d884d5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
427ab7bf
|
Leszek Koltunski
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
111 |
97dadfe5
|
Leszek Koltunski
|
{
|
112 |
6637d0f2
|
Leszek Koltunski
|
DistortedEffects.enableEffect(EffectNames.SWIRL);
|
113 |
|
|
DistortedEffects.enableEffect(EffectNames.SMOOTH_ALPHA);
|
114 |
|
|
DistortedEffects.enableEffect(EffectNames.SMOOTH_CHROMA);
|
115 |
|
|
DistortedEffects.enableEffect(EffectNames.DISTORT);
|
116 |
|
|
DistortedEffects.enableEffect(EffectNames.SINK);
|
117 |
|
|
|
118 |
427ab7bf
|
Leszek Koltunski
|
try
|
119 |
97dadfe5
|
Leszek Koltunski
|
{
|
120 |
76f9798b
|
Leszek Koltunski
|
Distorted.onCreate(mView.getContext());
|
121 |
97dadfe5
|
Leszek Koltunski
|
}
|
122 |
|
|
catch(Exception ex)
|
123 |
|
|
{
|
124 |
|
|
android.util.Log.e("Renderer", ex.getMessage() );
|
125 |
|
|
}
|
126 |
427ab7bf
|
Leszek Koltunski
|
}
|
127 |
|
|
|
128 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
|
|
|
130 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
131 |
|
|
{
|
132 |
97dadfe5
|
Leszek Koltunski
|
texW = width;
|
133 |
|
|
texH = height;
|
134 |
|
|
|
135 |
7451c98a
|
Leszek Koltunski
|
mTexture = new DistortedTexture(texW,texH);
|
136 |
f6d884d5
|
Leszek Koltunski
|
mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
|
137 |
|
|
mCanvas = new Canvas(mBitmap);
|
138 |
97dadfe5
|
Leszek Koltunski
|
|
139 |
fe59d375
|
Leszek Koltunski
|
mScreen.detachAll();
|
140 |
|
|
mScreen.attach(mTexture,mEffects,new MeshFlat(80,80*texH/texW));
|
141 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(texW, texH);
|
142 |
4562f295
|
Leszek Koltunski
|
mView.onSurfaceChanged(texW,texH);
|
143 |
fd89ecb6
|
Leszek Koltunski
|
|
144 |
|
|
mRefresh = true;
|
145 |
427ab7bf
|
Leszek Koltunski
|
}
|
146 |
|
|
|
147 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148 |
|
|
|
149 |
|
|
public void onDrawFrame(GL10 glUnused)
|
150 |
|
|
{
|
151 |
|
|
long time = System.currentTimeMillis();
|
152 |
|
|
|
153 |
3c8b1903
|
Leszek Koltunski
|
if (mView.getCurrentEffect() == MovingEffectsSurfaceView.EFFECT_POINTS && mRefresh )
|
154 |
427ab7bf
|
Leszek Koltunski
|
{
|
155 |
fd89ecb6
|
Leszek Koltunski
|
drawBackground();
|
156 |
4562f295
|
Leszek Koltunski
|
mView.drawCurve(mCanvas,time);
|
157 |
f6d884d5
|
Leszek Koltunski
|
mTexture.setTexture(mBitmap);
|
158 |
3c8b1903
|
Leszek Koltunski
|
mRefresh = false;
|
159 |
427ab7bf
|
Leszek Koltunski
|
}
|
160 |
|
|
|
161 |
fe59d375
|
Leszek Koltunski
|
mScreen.render(time);
|
162 |
427ab7bf
|
Leszek Koltunski
|
}
|
163 |
|
|
|
164 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165 |
|
|
}
|