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.EffectQuality;
|
25
|
import org.distorted.library.effect.PostprocessEffectGlow;
|
26
|
import org.distorted.library.effect.VertexEffectScale;
|
27
|
import org.distorted.library.main.DistortedEffects;
|
28
|
import org.distorted.library.main.DistortedLibrary;
|
29
|
import org.distorted.library.main.DistortedNode;
|
30
|
import org.distorted.library.main.DistortedScreen;
|
31
|
import org.distorted.library.main.DistortedTexture;
|
32
|
import org.distorted.library.mesh.MeshQuad;
|
33
|
import org.distorted.library.message.EffectListener;
|
34
|
import org.distorted.library.type.Dynamic2D;
|
35
|
import org.distorted.library.type.Dynamic4D;
|
36
|
import org.distorted.library.type.Static2D;
|
37
|
import org.distorted.library.type.Static4D;
|
38
|
|
39
|
import javax.microedition.khronos.egl.EGLConfig;
|
40
|
import javax.microedition.khronos.opengles.GL10;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
class FlatBlur2Renderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener, EffectListener
|
45
|
{
|
46
|
private static final int DUR_GLO = 2000;
|
47
|
|
48
|
private static final int[] colors = new int[] {0,0,1, 1,0,1, 1,0,0, 1,1,0, 0,1,0, 1,1,1}; // blue, pink, red, yellow, green, white
|
49
|
private static final int INDEX = 5;
|
50
|
|
51
|
private final GLSurfaceView mView;
|
52
|
private final DistortedScreen mScreen;
|
53
|
|
54
|
private DistortedNode mNode1, mNode2;
|
55
|
private long mGlowID;
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
FlatBlur2Renderer(GLSurfaceView v)
|
60
|
{
|
61
|
mView = v;
|
62
|
mScreen = new DistortedScreen();
|
63
|
|
64
|
DistortedTexture texture1 = new DistortedTexture();
|
65
|
texture1.setColorARGB(0xffff0000);
|
66
|
MeshQuad mesh1 = new MeshQuad();
|
67
|
DistortedEffects effects1 = new DistortedEffects();
|
68
|
VertexEffectScale mainScale= new VertexEffectScale(200);
|
69
|
effects1.apply(mainScale);
|
70
|
mNode1 = new DistortedNode(texture1,effects1,mesh1);
|
71
|
mScreen.attach(mNode1);
|
72
|
|
73
|
DistortedTexture texture2 = new DistortedTexture();
|
74
|
texture2.setColorARGB(0xffff0000);
|
75
|
MeshQuad mesh2 = new MeshQuad();
|
76
|
DistortedEffects effects2 = new DistortedEffects();
|
77
|
mNode2 = new DistortedNode(texture2,effects2,mesh2);
|
78
|
mScreen.attach(mNode2);
|
79
|
}
|
80
|
|
81
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82
|
|
83
|
public void onDrawFrame(GL10 glUnused)
|
84
|
{
|
85
|
mScreen.render(System.currentTimeMillis());
|
86
|
}
|
87
|
|
88
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89
|
|
90
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
91
|
{
|
92
|
mScreen.resize(width,height);
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
|
97
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
98
|
{
|
99
|
VertexEffectScale.enable();
|
100
|
PostprocessEffectGlow.enable();
|
101
|
DistortedLibrary.onSurfaceCreated( mView.getContext(), this);
|
102
|
}
|
103
|
|
104
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105
|
|
106
|
public void distortedException(Exception ex)
|
107
|
{
|
108
|
android.util.Log.e("FlatBlur2", ex.getMessage() );
|
109
|
}
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
public void crash()
|
114
|
{
|
115
|
Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,1.0f);
|
116
|
haloRadius.add(new Static2D( 0, 0));
|
117
|
haloRadius.add(new Static2D(15,50));
|
118
|
haloRadius.add(new Static2D( 0, 0));
|
119
|
|
120
|
Dynamic4D color= new Dynamic4D(DUR_GLO,1.0f);
|
121
|
Static4D P1 = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.0f);
|
122
|
Static4D P2 = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.5f);
|
123
|
color.add(P1);
|
124
|
color.add(P2);
|
125
|
color.add(P1);
|
126
|
|
127
|
PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
|
128
|
glow.setQuality(EffectQuality.MEDIUM);
|
129
|
mGlowID = glow.getID();
|
130
|
glow.notifyWhenFinished(this);
|
131
|
DistortedEffects effects = mNode1.getEffects();
|
132
|
effects.apply(glow);
|
133
|
}
|
134
|
|
135
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136
|
|
137
|
public void effectFinished(long id)
|
138
|
{
|
139
|
if( id==mGlowID )
|
140
|
{
|
141
|
mScreen.detach(mNode1);
|
142
|
mNode1.markForDeletion();
|
143
|
mNode1=null;
|
144
|
mScreen.detach(mNode2);
|
145
|
mNode2.markForDeletion();
|
146
|
mNode2=null;
|
147
|
}
|
148
|
}
|
149
|
}
|