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