1 |
7ba38011
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
71c8884f
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
7ba38011
|
Leszek Koltunski
|
// //
|
6 |
71c8884f
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
7ba38011
|
Leszek Koltunski
|
// 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 |
71c8884f
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
7ba38011
|
Leszek Koltunski
|
// 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 |
71c8884f
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
7ba38011
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.examples.aroundtheworld;
|
21 |
|
|
|
22 |
|
|
import android.graphics.Bitmap;
|
23 |
|
|
import android.graphics.BitmapFactory;
|
24 |
|
|
import android.opengl.GLSurfaceView;
|
25 |
|
|
|
26 |
|
|
import org.distorted.examples.R;
|
27 |
d76638f1
|
leszek
|
import org.distorted.library.effect.EffectType;
|
28 |
885b9cca
|
leszek
|
import org.distorted.library.effect.FragmentEffectChroma;
|
29 |
|
|
import org.distorted.library.effect.FragmentEffectContrast;
|
30 |
fa9b6494
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectScale;
|
31 |
885b9cca
|
leszek
|
import org.distorted.library.effect.VertexEffectDistort;
|
32 |
|
|
import org.distorted.library.effect.VertexEffectPinch;
|
33 |
ba95a70b
|
Leszek Koltunski
|
import org.distorted.library.effect.VertexEffectScale;
|
34 |
885b9cca
|
leszek
|
import org.distorted.library.effect.VertexEffectSink;
|
35 |
|
|
import org.distorted.library.effect.VertexEffectSwirl;
|
36 |
e3900503
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
37 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
38 |
|
|
import org.distorted.library.main.DistortedScreen;
|
39 |
f3ca895f
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshRectangles;
|
40 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedTexture;
|
41 |
7ba38011
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
42 |
|
|
|
43 |
|
|
import java.io.IOException;
|
44 |
|
|
import java.io.InputStream;
|
45 |
|
|
|
46 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
47 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
48 |
|
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
|
|
class AroundTheWorldRenderer implements GLSurfaceView.Renderer
|
52 |
|
|
{
|
53 |
|
|
private GLSurfaceView mView;
|
54 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
55 |
59540ba2
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
56 |
d218d64e
|
leszek
|
private DistortedScreen mScreen;
|
57 |
f3ca895f
|
Leszek Koltunski
|
private MeshRectangles mMesh;
|
58 |
392e16fd
|
Leszek Koltunski
|
private AroundTheWorldEffectsManager mManager;
|
59 |
ba95a70b
|
Leszek Koltunski
|
private Static3D mScaleMatrix, mScaleVertex;
|
60 |
fa9b6494
|
Leszek Koltunski
|
|
61 |
7ba38011
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
|
|
AroundTheWorldRenderer(GLSurfaceView view)
|
64 |
|
|
{
|
65 |
ba95a70b
|
Leszek Koltunski
|
mScaleMatrix= new Static3D(1,1,1);
|
66 |
|
|
mScaleVertex= new Static3D(1,1,1);
|
67 |
fa9b6494
|
Leszek Koltunski
|
|
68 |
f6d884d5
|
Leszek Koltunski
|
mView = view;
|
69 |
392e16fd
|
Leszek Koltunski
|
mManager = new AroundTheWorldEffectsManager();
|
70 |
698ad0a8
|
Leszek Koltunski
|
mEffects = new DistortedEffects();
|
71 |
ba95a70b
|
Leszek Koltunski
|
mEffects.apply(new MatrixEffectScale(mScaleMatrix));
|
72 |
|
|
mEffects.apply(new VertexEffectScale(mScaleVertex));
|
73 |
fa9b6494
|
Leszek Koltunski
|
|
74 |
392e16fd
|
Leszek Koltunski
|
mManager.apply(mEffects);
|
75 |
e4330c89
|
Leszek Koltunski
|
mScreen = new DistortedScreen();
|
76 |
855ba24e
|
leszek
|
mScreen.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
77 |
7ba38011
|
Leszek Koltunski
|
}
|
78 |
|
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
2f20ae3a
|
Leszek Koltunski
|
|
81 |
4b34bb08
|
Leszek Koltunski
|
AroundTheWorldEffectsManager getManager()
|
82 |
2f20ae3a
|
Leszek Koltunski
|
{
|
83 |
392e16fd
|
Leszek Koltunski
|
return mManager;
|
84 |
2f20ae3a
|
Leszek Koltunski
|
}
|
85 |
|
|
|
86 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87 |
|
|
|
88 |
7ba38011
|
Leszek Koltunski
|
public void onDrawFrame(GL10 glUnused)
|
89 |
|
|
{
|
90 |
fe59d375
|
Leszek Koltunski
|
mScreen.render( System.currentTimeMillis() );
|
91 |
7ba38011
|
Leszek Koltunski
|
}
|
92 |
|
|
|
93 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
|
|
|
95 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
96 |
|
|
{
|
97 |
ba95a70b
|
Leszek Koltunski
|
float horiRatio = (float)width / mScaleVertex.get0();
|
98 |
|
|
float vertRatio = (float)height/ mScaleVertex.get1();
|
99 |
|
|
float factor = Math.min(horiRatio,vertRatio);
|
100 |
7ba38011
|
Leszek Koltunski
|
|
101 |
ba95a70b
|
Leszek Koltunski
|
mScaleMatrix.set( factor,factor,factor );
|
102 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(width,height);
|
103 |
7ba38011
|
Leszek Koltunski
|
}
|
104 |
|
|
|
105 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
|
107 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
108 |
e7a4ef16
|
Leszek Koltunski
|
{
|
109 |
7ba38011
|
Leszek Koltunski
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.face);
|
110 |
|
|
Bitmap bitmap;
|
111 |
|
|
|
112 |
|
|
try
|
113 |
|
|
{
|
114 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
115 |
|
|
}
|
116 |
|
|
finally
|
117 |
|
|
{
|
118 |
|
|
try
|
119 |
|
|
{
|
120 |
|
|
is.close();
|
121 |
|
|
}
|
122 |
|
|
catch(IOException e) { }
|
123 |
|
|
}
|
124 |
|
|
|
125 |
16b22aab
|
Leszek Koltunski
|
int objWidth = bitmap.getWidth();
|
126 |
|
|
int objHeight= bitmap.getHeight();
|
127 |
7ba38011
|
Leszek Koltunski
|
|
128 |
ba95a70b
|
Leszek Koltunski
|
mScaleVertex.set(objWidth,objHeight,1);
|
129 |
|
|
|
130 |
687263cc
|
Leszek Koltunski
|
if( mTexture==null ) mTexture = new DistortedTexture();
|
131 |
59540ba2
|
Leszek Koltunski
|
mTexture.setTexture(bitmap);
|
132 |
fe59d375
|
Leszek Koltunski
|
|
133 |
ba95a70b
|
Leszek Koltunski
|
if( mMesh==null ) mMesh = new MeshRectangles(30,30*objHeight/objWidth);
|
134 |
5f2a53b6
|
leszek
|
|
135 |
fe59d375
|
Leszek Koltunski
|
mScreen.detachAll();
|
136 |
5f2a53b6
|
leszek
|
mScreen.attach(mTexture, mEffects, mMesh);
|
137 |
e8b6aa95
|
Leszek Koltunski
|
|
138 |
fcb09e1f
|
Leszek Koltunski
|
DistortedLibrary.setMax(EffectType.VERTEX ,13);
|
139 |
e3900503
|
Leszek Koltunski
|
DistortedLibrary.setMax(EffectType.FRAGMENT, 9);
|
140 |
676c14da
|
Leszek Koltunski
|
|
141 |
ba95a70b
|
Leszek Koltunski
|
VertexEffectScale.enable();
|
142 |
885b9cca
|
leszek
|
VertexEffectDistort.enable();
|
143 |
|
|
VertexEffectSink.enable();
|
144 |
|
|
VertexEffectPinch.enable();
|
145 |
|
|
VertexEffectSwirl.enable();
|
146 |
|
|
FragmentEffectChroma.enable();
|
147 |
|
|
FragmentEffectContrast.enable();
|
148 |
6637d0f2
|
Leszek Koltunski
|
|
149 |
7ba38011
|
Leszek Koltunski
|
try
|
150 |
|
|
{
|
151 |
e3900503
|
Leszek Koltunski
|
DistortedLibrary.onCreate(mView.getContext());
|
152 |
7ba38011
|
Leszek Koltunski
|
}
|
153 |
|
|
catch(Exception ex)
|
154 |
|
|
{
|
155 |
|
|
android.util.Log.e("AroundTheWorld", ex.getMessage() );
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
}
|