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 |
|
|
import android.opengl.GLSurfaceView;
|
23 |
|
|
|
24 |
4b7152b6
|
Leszek Koltunski
|
import org.distorted.library.effect.PostprocessEffectGlow;
|
25 |
|
|
import org.distorted.library.effect.VertexEffectScale;
|
26 |
|
|
import org.distorted.library.main.DistortedEffects;
|
27 |
29fdea14
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
28 |
4b7152b6
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedNode;
|
29 |
29fdea14
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedScreen;
|
30 |
4b7152b6
|
Leszek Koltunski
|
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 |
29fdea14
|
Leszek Koltunski
|
|
35 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
36 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
37 |
|
|
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
835cd7eb
|
Leszek Koltunski
|
class FlatBlur2Renderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
41 |
29fdea14
|
Leszek Koltunski
|
{
|
42 |
|
|
private final GLSurfaceView mView;
|
43 |
|
|
private final DistortedScreen mScreen;
|
44 |
835cd7eb
|
Leszek Koltunski
|
private final DistortedNode mNode;
|
45 |
29fdea14
|
Leszek Koltunski
|
|
46 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47 |
|
|
|
48 |
|
|
FlatBlur2Renderer(GLSurfaceView v)
|
49 |
|
|
{
|
50 |
|
|
mView = v;
|
51 |
|
|
mScreen = new DistortedScreen();
|
52 |
9a645457
|
Leszek Koltunski
|
|
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 |
835cd7eb
|
Leszek Koltunski
|
mNode = new DistortedNode(texture1,effects1,mesh1);
|
60 |
|
|
mScreen.attach(mNode);
|
61 |
9a645457
|
Leszek Koltunski
|
|
62 |
|
|
DistortedTexture texture2 = new DistortedTexture();
|
63 |
|
|
texture2.setColorARGB(0xffff0000);
|
64 |
|
|
MeshQuad mesh2 = new MeshQuad();
|
65 |
|
|
DistortedEffects effects2 = new DistortedEffects();
|
66 |
835cd7eb
|
Leszek Koltunski
|
DistortedNode node2 = new DistortedNode(texture2,effects2,mesh2);
|
67 |
|
|
mScreen.attach(node2);
|
68 |
29fdea14
|
Leszek Koltunski
|
}
|
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 |
4b7152b6
|
Leszek Koltunski
|
VertexEffectScale.enable();
|
89 |
|
|
PostprocessEffectGlow.enable();
|
90 |
29fdea14
|
Leszek Koltunski
|
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 |
9a645457
|
Leszek Koltunski
|
public void crash()
|
103 |
29fdea14
|
Leszek Koltunski
|
{
|
104 |
835cd7eb
|
Leszek Koltunski
|
Static2D haloRadius = new Static2D(15,50);
|
105 |
|
|
Static4D color = new Static4D(1,1,1,1);
|
106 |
4b7152b6
|
Leszek Koltunski
|
PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
|
107 |
835cd7eb
|
Leszek Koltunski
|
DistortedEffects effects = mNode.getEffects();
|
108 |
4b7152b6
|
Leszek Koltunski
|
effects.apply(glow);
|
109 |
|
|
}
|
110 |
29fdea14
|
Leszek Koltunski
|
}
|