1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
package org.distorted.examples.flatblur2;
|
21
|
|
22
|
import android.opengl.GLSurfaceView;
|
23
|
|
24
|
import org.distorted.library.effect.PostprocessEffectGlow;
|
25
|
import org.distorted.library.effect.VertexEffectScale;
|
26
|
import org.distorted.library.main.DistortedEffects;
|
27
|
import org.distorted.library.main.DistortedLibrary;
|
28
|
import org.distorted.library.main.DistortedNode;
|
29
|
import org.distorted.library.main.DistortedScreen;
|
30
|
import org.distorted.library.main.DistortedTexture;
|
31
|
import org.distorted.library.mesh.MeshQuad;
|
32
|
import org.distorted.library.type.Static2D;
|
33
|
import org.distorted.library.type.Static4D;
|
34
|
|
35
|
import javax.microedition.khronos.egl.EGLConfig;
|
36
|
import javax.microedition.khronos.opengles.GL10;
|
37
|
|
38
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39
|
|
40
|
class FlatBlur2Renderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
41
|
{
|
42
|
private final GLSurfaceView mView;
|
43
|
private final DistortedScreen mScreen;
|
44
|
private final DistortedNode mNode;
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
FlatBlur2Renderer(GLSurfaceView v)
|
49
|
{
|
50
|
mView = v;
|
51
|
mScreen = new DistortedScreen();
|
52
|
|
53
|
DistortedTexture texture1 = new DistortedTexture();
|
54
|
texture1.setColorARGB(0xffff0000);
|
55
|
MeshQuad mesh1 = new MeshQuad();
|
56
|
DistortedEffects effects1 = new DistortedEffects();
|
57
|
VertexEffectScale mainScale= new VertexEffectScale(200);
|
58
|
effects1.apply(mainScale);
|
59
|
mNode = new DistortedNode(texture1,effects1,mesh1);
|
60
|
mScreen.attach(mNode);
|
61
|
|
62
|
DistortedTexture texture2 = new DistortedTexture();
|
63
|
texture2.setColorARGB(0xffff0000);
|
64
|
MeshQuad mesh2 = new MeshQuad();
|
65
|
DistortedEffects effects2 = new DistortedEffects();
|
66
|
DistortedNode node2 = new DistortedNode(texture2,effects2,mesh2);
|
67
|
mScreen.attach(node2);
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
|
72
|
public void onDrawFrame(GL10 glUnused)
|
73
|
{
|
74
|
mScreen.render(System.currentTimeMillis());
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
|
79
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
80
|
{
|
81
|
mScreen.resize(width,height);
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
|
86
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
87
|
{
|
88
|
VertexEffectScale.enable();
|
89
|
PostprocessEffectGlow.enable();
|
90
|
DistortedLibrary.onSurfaceCreated( mView.getContext(), this);
|
91
|
}
|
92
|
|
93
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94
|
|
95
|
public void distortedException(Exception ex)
|
96
|
{
|
97
|
android.util.Log.e("FlatBlur2", ex.getMessage() );
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
public void crash()
|
103
|
{
|
104
|
Static2D haloRadius = new Static2D(15,50);
|
105
|
Static4D color = new Static4D(1,1,1,1);
|
106
|
PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
|
107
|
DistortedEffects effects = mNode.getEffects();
|
108
|
effects.apply(glow);
|
109
|
}
|
110
|
}
|