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