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 |
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.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 |
f988589e
|
Leszek Koltunski
|
public class DynamicRenderer implements GLSurfaceView.Renderer
|
40 |
427ab7bf
|
Leszek Koltunski
|
{
|
41 |
|
|
public static final int BWID = 300;
|
42 |
|
|
public static final int BHEI = 400;
|
43 |
|
|
|
44 |
|
|
private GLSurfaceView mView;
|
45 |
|
|
private DistortedBitmap mBackground;
|
46 |
|
|
private Canvas mCanvas;
|
47 |
|
|
private Bitmap mBitmap;
|
48 |
|
|
private Paint mPaint;
|
49 |
|
|
private int texWidth, texHeight;
|
50 |
|
|
|
51 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52 |
|
|
|
53 |
f988589e
|
Leszek Koltunski
|
public DynamicRenderer(GLSurfaceView v)
|
54 |
427ab7bf
|
Leszek Koltunski
|
{
|
55 |
|
|
mPaint = new Paint();
|
56 |
|
|
mPaint.setAntiAlias(true);
|
57 |
|
|
mPaint.setFakeBoldText(true);
|
58 |
|
|
mPaint.setColor(0xff447da7);
|
59 |
|
|
mPaint.setStyle(Style.FILL);
|
60 |
|
|
|
61 |
|
|
mView = v;
|
62 |
|
|
|
63 |
|
|
texWidth = BWID;
|
64 |
|
|
texHeight= BHEI;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
|
69 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
70 |
|
|
{
|
71 |
|
|
mBackground = new DistortedBitmap(texWidth,texHeight, 2);
|
72 |
|
|
mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
|
73 |
|
|
mCanvas = new Canvas(mBitmap);
|
74 |
|
|
|
75 |
|
|
try
|
76 |
|
|
{
|
77 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
78 |
427ab7bf
|
Leszek Koltunski
|
}
|
79 |
|
|
catch(Exception ex)
|
80 |
|
|
{
|
81 |
|
|
android.util.Log.e("Renderer", ex.getMessage() );
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86 |
|
|
|
87 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
88 |
|
|
{
|
89 |
a8c3ada7
|
Leszek Koltunski
|
mBackground.abortEffects(EffectTypes.MATRIX);
|
90 |
7589635e
|
Leszek Koltunski
|
mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
|
91 |
427ab7bf
|
Leszek Koltunski
|
Distorted.onSurfaceChanged(width, height);
|
92 |
f988589e
|
Leszek Koltunski
|
DynamicSurfaceView.setScreenSize(width,height);
|
93 |
427ab7bf
|
Leszek Koltunski
|
}
|
94 |
|
|
|
95 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96 |
|
|
|
97 |
|
|
public void onDrawFrame(GL10 glUnused)
|
98 |
|
|
{
|
99 |
|
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
|
100 |
|
|
|
101 |
|
|
long time = System.currentTimeMillis();
|
102 |
|
|
|
103 |
|
|
mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
|
104 |
f988589e
|
Leszek Koltunski
|
DynamicSurfaceView.drawCurve(mCanvas,time);
|
105 |
427ab7bf
|
Leszek Koltunski
|
mBackground.setBitmap(mBitmap);
|
106 |
|
|
mBackground.draw(time);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110 |
|
|
}
|