1 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
71c8884f
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
bc0a685b
|
Leszek Koltunski
|
// //
|
6 |
71c8884f
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
bc0a685b
|
Leszek Koltunski
|
// 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 |
71c8884f
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
bc0a685b
|
Leszek Koltunski
|
// 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 |
71c8884f
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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.GLSurfaceView;
|
30 |
|
|
|
31 |
1fc23462
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectScale;
|
32 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
33 |
|
|
import org.distorted.library.main.DistortedScreen;
|
34 |
f3ca895f
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshRectangles;
|
35 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedTexture;
|
36 |
e3900503
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
37 |
1fc23462
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
38 |
427ab7bf
|
Leszek Koltunski
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
97dadfe5
|
Leszek Koltunski
|
class DynamicRenderer implements GLSurfaceView.Renderer
|
42 |
427ab7bf
|
Leszek Koltunski
|
{
|
43 |
fe3c72ce
|
Leszek Koltunski
|
private DynamicSurfaceView mView;
|
44 |
40eef4b9
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
45 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
46 |
d218d64e
|
leszek
|
private DistortedScreen mScreen;
|
47 |
f3ca895f
|
Leszek Koltunski
|
private MeshRectangles mMesh;
|
48 |
427ab7bf
|
Leszek Koltunski
|
private Canvas mCanvas;
|
49 |
|
|
private Bitmap mBitmap;
|
50 |
|
|
private Paint mPaint;
|
51 |
1fc23462
|
Leszek Koltunski
|
private Static3D mScale;
|
52 |
2666a48c
|
Leszek Koltunski
|
private static int texW, texH;
|
53 |
427ab7bf
|
Leszek Koltunski
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
fe3c72ce
|
Leszek Koltunski
|
DynamicRenderer(DynamicSurfaceView v)
|
57 |
427ab7bf
|
Leszek Koltunski
|
{
|
58 |
|
|
mPaint = new Paint();
|
59 |
|
|
mPaint.setAntiAlias(true);
|
60 |
|
|
mPaint.setFakeBoldText(true);
|
61 |
|
|
mPaint.setColor(0xff447da7);
|
62 |
|
|
mPaint.setStyle(Style.FILL);
|
63 |
|
|
|
64 |
fe59d375
|
Leszek Koltunski
|
mView = v;
|
65 |
f3ca895f
|
Leszek Koltunski
|
mMesh = new MeshRectangles(1,1);
|
66 |
e4330c89
|
Leszek Koltunski
|
mScreen = new DistortedScreen();
|
67 |
698ad0a8
|
Leszek Koltunski
|
mEffects = new DistortedEffects();
|
68 |
1fc23462
|
Leszek Koltunski
|
mTexture = new DistortedTexture();
|
69 |
|
|
|
70 |
|
|
mScale = new Static3D(1,1,1);
|
71 |
|
|
mEffects.apply( new MatrixEffectScale(mScale) );
|
72 |
427ab7bf
|
Leszek Koltunski
|
}
|
73 |
|
|
|
74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
|
|
76 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
77 |
|
|
{
|
78 |
|
|
try
|
79 |
3c8b1903
|
Leszek Koltunski
|
{
|
80 |
e3900503
|
Leszek Koltunski
|
DistortedLibrary.onCreate(mView.getContext());
|
81 |
3c8b1903
|
Leszek Koltunski
|
}
|
82 |
|
|
catch(Exception ex)
|
83 |
|
|
{
|
84 |
|
|
android.util.Log.e("Renderer", ex.getMessage() );
|
85 |
|
|
}
|
86 |
427ab7bf
|
Leszek Koltunski
|
}
|
87 |
|
|
|
88 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
|
|
|
90 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
91 |
|
|
{
|
92 |
97dadfe5
|
Leszek Koltunski
|
texW = width;
|
93 |
|
|
texH = height;
|
94 |
|
|
|
95 |
1fc23462
|
Leszek Koltunski
|
mScale.set(width,height,1);
|
96 |
2666a48c
|
Leszek Koltunski
|
|
97 |
40eef4b9
|
Leszek Koltunski
|
mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
|
98 |
|
|
mCanvas = new Canvas(mBitmap);
|
99 |
97dadfe5
|
Leszek Koltunski
|
|
100 |
fe59d375
|
Leszek Koltunski
|
mScreen.detachAll();
|
101 |
|
|
mScreen.attach(mTexture,mEffects,mMesh);
|
102 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(texW,texH);
|
103 |
fe3c72ce
|
Leszek Koltunski
|
mView.onSurfaceChanged(texW,texH);
|
104 |
1fc23462
|
Leszek Koltunski
|
DynamicSurfaceView.surfaceChanged(texW,texH);
|
105 |
427ab7bf
|
Leszek Koltunski
|
}
|
106 |
|
|
|
107 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
|
109 |
|
|
public void onDrawFrame(GL10 glUnused)
|
110 |
|
|
{
|
111 |
|
|
long time = System.currentTimeMillis();
|
112 |
|
|
|
113 |
97dadfe5
|
Leszek Koltunski
|
mCanvas.drawRect(0, 0, texW, texH, mPaint);
|
114 |
fe3c72ce
|
Leszek Koltunski
|
mView.drawCurve(mCanvas,time);
|
115 |
40eef4b9
|
Leszek Koltunski
|
mTexture.setTexture(mBitmap);
|
116 |
fe59d375
|
Leszek Koltunski
|
mScreen.render( System.currentTimeMillis() );
|
117 |
427ab7bf
|
Leszek Koltunski
|
}
|
118 |
|
|
}
|