1 |
bc0a685b
|
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 |
427ab7bf
|
Leszek Koltunski
|
|
20 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.fbo;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
22 |
|
|
import java.io.IOException;
|
23 |
|
|
import java.io.InputStream;
|
24 |
|
|
|
25 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
26 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
27 |
|
|
|
28 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.examples.R;
|
29 |
427ab7bf
|
Leszek Koltunski
|
|
30 |
d04a4886
|
Leszek Koltunski
|
import org.distorted.library.DistortedEffects;
|
31 |
392e16fd
|
Leszek Koltunski
|
import org.distorted.library.DistortedFramebuffer;
|
32 |
d04a4886
|
Leszek Koltunski
|
import org.distorted.library.DistortedTree;
|
33 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
34 |
c0486401
|
Leszek Koltunski
|
import org.distorted.library.GridCubes;
|
35 |
10b7e588
|
Leszek Koltunski
|
import org.distorted.library.GridFlat;
|
36 |
f6d884d5
|
Leszek Koltunski
|
import org.distorted.library.DistortedTexture;
|
37 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
38 |
c0486401
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic;
|
39 |
59759251
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic1D;
|
40 |
|
|
import org.distorted.library.type.Static1D;
|
41 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
42 |
427ab7bf
|
Leszek Koltunski
|
|
43 |
|
|
import android.graphics.Bitmap;
|
44 |
|
|
import android.graphics.BitmapFactory;
|
45 |
|
|
import android.opengl.GLES20;
|
46 |
|
|
import android.opengl.GLSurfaceView;
|
47 |
|
|
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49 |
|
|
|
50 |
|
|
class FBORenderer implements GLSurfaceView.Renderer
|
51 |
|
|
{
|
52 |
|
|
private GLSurfaceView mView;
|
53 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
54 |
392e16fd
|
Leszek Koltunski
|
private DistortedFramebuffer mScreen;
|
55 |
d04a4886
|
Leszek Koltunski
|
private DistortedTree mRoot;
|
56 |
392e16fd
|
Leszek Koltunski
|
private int lisaHeight, lisaWidth;
|
57 |
|
|
|
58 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
|
|
|
60 |
7e6110e2
|
Leszek Koltunski
|
FBORenderer(GLSurfaceView v)
|
61 |
427ab7bf
|
Leszek Koltunski
|
{
|
62 |
392e16fd
|
Leszek Koltunski
|
mView = v;
|
63 |
d04a4886
|
Leszek Koltunski
|
mEffects= new DistortedEffects();
|
64 |
392e16fd
|
Leszek Koltunski
|
mScreen = new DistortedFramebuffer(0);
|
65 |
427ab7bf
|
Leszek Koltunski
|
}
|
66 |
|
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
|
69 |
|
|
public void onDrawFrame(GL10 glUnused)
|
70 |
|
|
{
|
71 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
72 |
bc29e409
|
Leszek Koltunski
|
mScreen.renderTo(mRoot,System.currentTimeMillis());
|
73 |
427ab7bf
|
Leszek Koltunski
|
}
|
74 |
|
|
|
75 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
|
|
|
77 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
78 |
|
|
{
|
79 |
392e16fd
|
Leszek Koltunski
|
mEffects.abortEffects(EffectTypes.MATRIX);
|
80 |
427ab7bf
|
Leszek Koltunski
|
|
81 |
5055b5d4
|
Leszek Koltunski
|
if( (float)lisaHeight/lisaWidth > (float)height/width )
|
82 |
427ab7bf
|
Leszek Koltunski
|
{
|
83 |
|
|
int w = (height*lisaWidth)/lisaHeight;
|
84 |
7589635e
|
Leszek Koltunski
|
float factor = (float)height/lisaHeight;
|
85 |
|
|
|
86 |
392e16fd
|
Leszek Koltunski
|
mEffects.move( new Static3D((width-w)/2,0,0) );
|
87 |
|
|
mEffects.scale(factor);
|
88 |
427ab7bf
|
Leszek Koltunski
|
}
|
89 |
|
|
else
|
90 |
|
|
{
|
91 |
|
|
int h = (width*lisaHeight)/lisaWidth;
|
92 |
7589635e
|
Leszek Koltunski
|
float factor = (float)width/lisaWidth;
|
93 |
|
|
|
94 |
392e16fd
|
Leszek Koltunski
|
mEffects.move( new Static3D(0,(height-h)/2,0) );
|
95 |
|
|
mEffects.scale(factor);
|
96 |
427ab7bf
|
Leszek Koltunski
|
}
|
97 |
|
|
|
98 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(width, height);
|
99 |
427ab7bf
|
Leszek Koltunski
|
}
|
100 |
|
|
|
101 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
104 |
|
|
{
|
105 |
e7a4ef16
|
Leszek Koltunski
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
106 |
|
|
|
107 |
427ab7bf
|
Leszek Koltunski
|
InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.monalisa);
|
108 |
c0486401
|
Leszek Koltunski
|
InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.grid);
|
109 |
427ab7bf
|
Leszek Koltunski
|
|
110 |
|
|
Bitmap bitmap1, bitmap2;
|
111 |
|
|
|
112 |
|
|
try
|
113 |
|
|
{
|
114 |
|
|
bitmap1 = BitmapFactory.decodeStream(is1);
|
115 |
|
|
bitmap2 = BitmapFactory.decodeStream(is2);
|
116 |
|
|
}
|
117 |
|
|
finally
|
118 |
|
|
{
|
119 |
|
|
try
|
120 |
|
|
{
|
121 |
|
|
is1.close();
|
122 |
|
|
is2.close();
|
123 |
|
|
}
|
124 |
|
|
catch(IOException e) { }
|
125 |
|
|
}
|
126 |
|
|
|
127 |
f6d884d5
|
Leszek Koltunski
|
lisaWidth = bitmap1.getWidth();
|
128 |
|
|
lisaHeight = bitmap1.getHeight();
|
129 |
|
|
int textWidth = bitmap2.getWidth();
|
130 |
|
|
int textHeight= bitmap2.getHeight();
|
131 |
|
|
|
132 |
7451c98a
|
Leszek Koltunski
|
DistortedTexture lisa = new DistortedTexture(lisaWidth,lisaHeight);
|
133 |
|
|
DistortedTexture text = new DistortedTexture(textWidth,textHeight);
|
134 |
f6d884d5
|
Leszek Koltunski
|
lisa.setTexture(bitmap1);
|
135 |
e8b6aa95
|
Leszek Koltunski
|
text.setTexture(bitmap2);
|
136 |
d04a4886
|
Leszek Koltunski
|
DistortedEffects textEffects = new DistortedEffects();
|
137 |
e8b6aa95
|
Leszek Koltunski
|
|
138 |
392e16fd
|
Leszek Koltunski
|
mEffects.abortAllEffects();
|
139 |
fd89ecb6
|
Leszek Koltunski
|
|
140 |
d04a4886
|
Leszek Koltunski
|
mRoot = new DistortedTree(lisa, mEffects,new GridFlat(1,1));
|
141 |
|
|
mRoot.attach(text,textEffects,new GridCubes(20,5,false));
|
142 |
7589635e
|
Leszek Koltunski
|
|
143 |
c0486401
|
Leszek Koltunski
|
float factor = lisaWidth/(2.0f*textWidth);
|
144 |
7589635e
|
Leszek Koltunski
|
|
145 |
d04a4886
|
Leszek Koltunski
|
textEffects.move( new Static3D( (lisaWidth-factor*textWidth)/2,(lisaHeight-factor*textHeight)/2,0) );
|
146 |
|
|
textEffects.scale(factor);
|
147 |
7bf107f7
|
Leszek Koltunski
|
|
148 |
c0486401
|
Leszek Koltunski
|
Dynamic1D rotDyn = new Dynamic1D(12000,0.0f);
|
149 |
|
|
rotDyn.add(new Static1D( 0));
|
150 |
|
|
rotDyn.add(new Static1D(360));
|
151 |
|
|
rotDyn.setMode(Dynamic.MODE_JUMP);
|
152 |
|
|
|
153 |
d04a4886
|
Leszek Koltunski
|
textEffects.rotate(rotDyn, new Static3D(1,0,0), new Static3D(textWidth/2,textHeight/2,textHeight/10) );
|
154 |
c0486401
|
Leszek Koltunski
|
|
155 |
|
|
Dynamic1D sinkDyn = new Dynamic1D(3000,0.0f);
|
156 |
7bf107f7
|
Leszek Koltunski
|
sinkDyn.add(new Static1D(1.0f));
|
157 |
c0486401
|
Leszek Koltunski
|
sinkDyn.add(new Static1D(0.3f));
|
158 |
7bf107f7
|
Leszek Koltunski
|
|
159 |
d04a4886
|
Leszek Koltunski
|
textEffects.sink(sinkDyn, new Static3D(textWidth/2,textHeight/2, 0));
|
160 |
59759251
|
Leszek Koltunski
|
|
161 |
c0486401
|
Leszek Koltunski
|
Dynamic1D chromaDyn = new Dynamic1D(5000,0.0f);
|
162 |
70d7a31f
|
Leszek Koltunski
|
chromaDyn.add(new Static1D(0.0f));
|
163 |
c0486401
|
Leszek Koltunski
|
chromaDyn.add(new Static1D(1.0f));
|
164 |
59759251
|
Leszek Koltunski
|
|
165 |
392e16fd
|
Leszek Koltunski
|
mEffects.chroma(chromaDyn, new Static3D(0,0,1) );
|
166 |
427ab7bf
|
Leszek Koltunski
|
|
167 |
|
|
try
|
168 |
|
|
{
|
169 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
170 |
427ab7bf
|
Leszek Koltunski
|
}
|
171 |
|
|
catch(Exception ex)
|
172 |
|
|
{
|
173 |
e8b6aa95
|
Leszek Koltunski
|
android.util.Log.e("FBO", ex.getMessage() );
|
174 |
427ab7bf
|
Leszek Koltunski
|
}
|
175 |
|
|
}
|
176 |
|
|
}
|