1 |
29fdea14
|
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 |
|
|
package org.distorted.examples.flatblur2;
|
21 |
|
|
|
22 |
99a80c08
|
Leszek Koltunski
|
import android.content.res.Resources;
|
23 |
29fdea14
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
24 |
|
|
|
25 |
99a80c08
|
Leszek Koltunski
|
import org.distorted.library.effect.EffectQuality;
|
26 |
|
|
import org.distorted.library.effect.EffectType;
|
27 |
|
|
import org.distorted.library.effect.MatrixEffectRotate;
|
28 |
|
|
import org.distorted.library.effect.MatrixEffectScale;
|
29 |
4b7152b6
|
Leszek Koltunski
|
import org.distorted.library.effect.PostprocessEffectGlow;
|
30 |
|
|
import org.distorted.library.main.DistortedEffects;
|
31 |
29fdea14
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
32 |
4b7152b6
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedNode;
|
33 |
29fdea14
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedScreen;
|
34 |
4b7152b6
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedTexture;
|
35 |
99a80c08
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshCubes;
|
36 |
4b7152b6
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshQuad;
|
37 |
99a80c08
|
Leszek Koltunski
|
|
38 |
|
|
import org.distorted.library.message.EffectListener;
|
39 |
|
|
import org.distorted.library.type.Dynamic2D;
|
40 |
|
|
import org.distorted.library.type.Dynamic4D;
|
41 |
|
|
import org.distorted.library.type.Static1D;
|
42 |
4b7152b6
|
Leszek Koltunski
|
import org.distorted.library.type.Static2D;
|
43 |
99a80c08
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
44 |
4b7152b6
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
45 |
29fdea14
|
Leszek Koltunski
|
|
46 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
47 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
48 |
|
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
99a80c08
|
Leszek Koltunski
|
class FlatBlur2Renderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener, ListenerOverlay, EffectListener
|
52 |
29fdea14
|
Leszek Koltunski
|
{
|
53 |
|
|
private final GLSurfaceView mView;
|
54 |
|
|
private final DistortedScreen mScreen;
|
55 |
99a80c08
|
Leszek Koltunski
|
private Static3D mScale1, mScale2;
|
56 |
|
|
private DistortedNode mNode;
|
57 |
29fdea14
|
Leszek Koltunski
|
|
58 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
|
|
|
60 |
|
|
FlatBlur2Renderer(GLSurfaceView v)
|
61 |
|
|
{
|
62 |
|
|
mView = v;
|
63 |
|
|
mScreen = new DistortedScreen();
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
|
68 |
|
|
public void onDrawFrame(GL10 glUnused)
|
69 |
|
|
{
|
70 |
|
|
mScreen.render(System.currentTimeMillis());
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
|
|
|
75 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
76 |
|
|
{
|
77 |
99a80c08
|
Leszek Koltunski
|
float s = width*0.05f;
|
78 |
|
|
mScale1.set(width,width,0);
|
79 |
|
|
mScale2.set(s,s,s);
|
80 |
29fdea14
|
Leszek Koltunski
|
mScreen.resize(width,height);
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
86 |
|
|
{
|
87 |
99a80c08
|
Leszek Koltunski
|
DistortedTexture surface1 = new DistortedTexture();
|
88 |
|
|
surface1.setColorARGB(0xffff0000);
|
89 |
|
|
MeshQuad mesh1 = new MeshQuad();
|
90 |
|
|
DistortedEffects effects1 = new DistortedEffects();
|
91 |
|
|
|
92 |
|
|
mScale1 = new Static3D(1,1,1);
|
93 |
|
|
MatrixEffectScale scale1 = new MatrixEffectScale(mScale1);
|
94 |
|
|
effects1.apply(scale1);
|
95 |
|
|
mNode = new DistortedNode(surface1,effects1,mesh1);
|
96 |
|
|
mScreen.attach(mNode);
|
97 |
|
|
|
98 |
|
|
DistortedTexture surface2 = new DistortedTexture();
|
99 |
|
|
surface2.setColorARGB(0xff0000ff);
|
100 |
|
|
MeshCubes mesh2 = new MeshCubes(2,2,2);
|
101 |
|
|
DistortedEffects effects2 = new DistortedEffects();
|
102 |
|
|
|
103 |
|
|
mScale2 = new Static3D(1,1,1);
|
104 |
|
|
MatrixEffectScale scale2 = new MatrixEffectScale(mScale2);
|
105 |
|
|
effects2.apply(scale2);
|
106 |
|
|
Static1D angle = new Static1D(30);
|
107 |
|
|
float SQ3 = (float)Math.sqrt(3);
|
108 |
|
|
Static3D axis = new Static3D(SQ3/3,SQ3/3,SQ3/3);
|
109 |
|
|
Static3D center = new Static3D(0,0,0);
|
110 |
|
|
MatrixEffectRotate rot = new MatrixEffectRotate(angle,axis,center);
|
111 |
|
|
effects2.apply(rot);
|
112 |
|
|
DistortedNode node2 = new DistortedNode(surface2,effects2,mesh2);
|
113 |
|
|
mNode.attach(node2);
|
114 |
|
|
|
115 |
|
|
OverlayStars.enableEffects();
|
116 |
29fdea14
|
Leszek Koltunski
|
DistortedLibrary.onSurfaceCreated( mView.getContext(), this);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
|
121 |
|
|
public void distortedException(Exception ex)
|
122 |
|
|
{
|
123 |
|
|
android.util.Log.e("FlatBlur2", ex.getMessage() );
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
127 |
|
|
|
128 |
99a80c08
|
Leszek Koltunski
|
public void button1()
|
129 |
29fdea14
|
Leszek Koltunski
|
{
|
130 |
99a80c08
|
Leszek Koltunski
|
OverlayStars stars = new OverlayStars();
|
131 |
|
|
Resources res = mView.getResources();
|
132 |
|
|
DataStars data = new DataStars(10,5,res);
|
133 |
|
|
stars.startOverlay(mScreen,this,data);
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
137 |
|
|
|
138 |
|
|
public void button2()
|
139 |
|
|
{
|
140 |
|
|
PostprocessEffectGlow glow = constructGlow();
|
141 |
835cd7eb
|
Leszek Koltunski
|
DistortedEffects effects = mNode.getEffects();
|
142 |
4b7152b6
|
Leszek Koltunski
|
effects.apply(glow);
|
143 |
|
|
}
|
144 |
99a80c08
|
Leszek Koltunski
|
|
145 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
|
|
|
147 |
|
|
private PostprocessEffectGlow constructGlow()
|
148 |
|
|
{
|
149 |
|
|
final int DUR_GLO = 3000;
|
150 |
|
|
Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,0.5f);
|
151 |
|
|
Static2D point20 = new Static2D( 0, 0);
|
152 |
|
|
Static2D point21 = new Static2D(15,50);
|
153 |
|
|
Dynamic4D color = new Dynamic4D(DUR_GLO, 0.5f);
|
154 |
|
|
Static4D point40 = new Static4D(1,1,1,0.0f);
|
155 |
|
|
Static4D point41 = new Static4D(1,1,1,0.8f);
|
156 |
|
|
|
157 |
|
|
haloRadius.add(point20);
|
158 |
|
|
haloRadius.add(point21);
|
159 |
|
|
haloRadius.add(point20);
|
160 |
|
|
color.add(point40);
|
161 |
|
|
color.add(point41);
|
162 |
|
|
color.add(point40);
|
163 |
|
|
|
164 |
|
|
PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
|
165 |
|
|
glow.setQuality(EffectQuality.MEDIUM);
|
166 |
|
|
glow.notifyWhenFinished(this);
|
167 |
|
|
return glow;
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171 |
|
|
|
172 |
|
|
public void overlayFinished(long id)
|
173 |
|
|
{
|
174 |
|
|
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178 |
|
|
|
179 |
|
|
public void effectFinished(long id)
|
180 |
|
|
{
|
181 |
|
|
DistortedEffects effects = mNode.getEffects();
|
182 |
|
|
effects.abortByType(EffectType.POSTPROCESS);
|
183 |
|
|
}
|
184 |
29fdea14
|
Leszek Koltunski
|
}
|