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 |
10b7e588
|
Leszek Koltunski
|
import org.distorted.library.GridFlat;
|
33 |
e8b6aa95
|
Leszek Koltunski
|
import org.distorted.library.DistortedObject;
|
34 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
35 |
427ab7bf
|
Leszek Koltunski
|
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
97dadfe5
|
Leszek Koltunski
|
class DynamicRenderer implements GLSurfaceView.Renderer
|
39 |
427ab7bf
|
Leszek Koltunski
|
{
|
40 |
fe3c72ce
|
Leszek Koltunski
|
private DynamicSurfaceView mView;
|
41 |
e8b6aa95
|
Leszek Koltunski
|
private DistortedObject mBackground;
|
42 |
10b7e588
|
Leszek Koltunski
|
private GridFlat mGrid;
|
43 |
427ab7bf
|
Leszek Koltunski
|
private Canvas mCanvas;
|
44 |
|
|
private Bitmap mBitmap;
|
45 |
|
|
private Paint mPaint;
|
46 |
97dadfe5
|
Leszek Koltunski
|
|
47 |
|
|
static int texW, texH;
|
48 |
427ab7bf
|
Leszek Koltunski
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
fe3c72ce
|
Leszek Koltunski
|
DynamicRenderer(DynamicSurfaceView v)
|
52 |
427ab7bf
|
Leszek Koltunski
|
{
|
53 |
|
|
mPaint = new Paint();
|
54 |
|
|
mPaint.setAntiAlias(true);
|
55 |
|
|
mPaint.setFakeBoldText(true);
|
56 |
|
|
mPaint.setColor(0xff447da7);
|
57 |
|
|
mPaint.setStyle(Style.FILL);
|
58 |
|
|
|
59 |
|
|
mView = v;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
|
|
|
64 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
65 |
|
|
{
|
66 |
|
|
try
|
67 |
|
|
{
|
68 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
69 |
427ab7bf
|
Leszek Koltunski
|
}
|
70 |
|
|
catch(Exception ex)
|
71 |
|
|
{
|
72 |
|
|
android.util.Log.e("Renderer", ex.getMessage() );
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77 |
|
|
|
78 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
79 |
|
|
{
|
80 |
97dadfe5
|
Leszek Koltunski
|
texW = width;
|
81 |
|
|
texH = height;
|
82 |
|
|
|
83 |
10b7e588
|
Leszek Koltunski
|
mGrid = new GridFlat(1,1);
|
84 |
e8b6aa95
|
Leszek Koltunski
|
mBackground = new DistortedObject(texW,texH,1);
|
85 |
|
|
mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
|
86 |
|
|
mCanvas = new Canvas(mBitmap);
|
87 |
97dadfe5
|
Leszek Koltunski
|
|
88 |
|
|
Distorted.onSurfaceChanged(texW,texH);
|
89 |
fe3c72ce
|
Leszek Koltunski
|
mView.onSurfaceChanged(texW,texH);
|
90 |
427ab7bf
|
Leszek Koltunski
|
}
|
91 |
|
|
|
92 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93 |
|
|
|
94 |
|
|
public void onDrawFrame(GL10 glUnused)
|
95 |
|
|
{
|
96 |
|
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
|
97 |
|
|
|
98 |
|
|
long time = System.currentTimeMillis();
|
99 |
|
|
|
100 |
97dadfe5
|
Leszek Koltunski
|
mCanvas.drawRect(0, 0, texW, texH, mPaint);
|
101 |
fe3c72ce
|
Leszek Koltunski
|
mView.drawCurve(mCanvas,time);
|
102 |
e8b6aa95
|
Leszek Koltunski
|
mBackground.setTexture(mBitmap);
|
103 |
|
|
mBackground.draw(time,mGrid);
|
104 |
427ab7bf
|
Leszek Koltunski
|
}
|
105 |
|
|
|
106 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107 |
|
|
}
|