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 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.DistortedNode;
|
31 |
|
|
import org.distorted.library.Distorted;
|
32 |
|
|
import org.distorted.library.DistortedBitmap;
|
33 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
34 |
59759251
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic1D;
|
35 |
|
|
import org.distorted.library.type.Static1D;
|
36 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static2D;
|
37 |
|
|
import org.distorted.library.type.Static3D;
|
38 |
427ab7bf
|
Leszek Koltunski
|
|
39 |
|
|
import android.graphics.Bitmap;
|
40 |
|
|
import android.graphics.BitmapFactory;
|
41 |
|
|
import android.opengl.GLES20;
|
42 |
|
|
import android.opengl.GLSurfaceView;
|
43 |
|
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
|
|
class FBORenderer implements GLSurfaceView.Renderer
|
47 |
|
|
{
|
48 |
|
|
private GLSurfaceView mView;
|
49 |
|
|
private DistortedBitmap mLisa, mText;
|
50 |
|
|
private int lisaHeight, lisaWidth;
|
51 |
|
|
|
52 |
|
|
private DistortedNode mRoot;
|
53 |
|
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
|
|
public FBORenderer(GLSurfaceView v)
|
57 |
|
|
{
|
58 |
|
|
mView = v;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
|
|
public void onDrawFrame(GL10 glUnused)
|
64 |
|
|
{
|
65 |
|
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
66 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
67 |
|
|
|
68 |
|
|
mRoot.draw(System.currentTimeMillis());
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72 |
|
|
|
73 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
74 |
|
|
{
|
75 |
a8c3ada7
|
Leszek Koltunski
|
mLisa.abortEffects(EffectTypes.MATRIX);
|
76 |
427ab7bf
|
Leszek Koltunski
|
|
77 |
|
|
if( lisaHeight/lisaWidth > height/width )
|
78 |
|
|
{
|
79 |
|
|
int w = (height*lisaWidth)/lisaHeight;
|
80 |
7589635e
|
Leszek Koltunski
|
float factor = (float)height/lisaHeight;
|
81 |
|
|
|
82 |
|
|
mLisa.move( new Static3D((width-w)/2,0,0) );
|
83 |
f988589e
|
Leszek Koltunski
|
mLisa.scale(factor);
|
84 |
427ab7bf
|
Leszek Koltunski
|
}
|
85 |
|
|
else
|
86 |
|
|
{
|
87 |
|
|
int h = (width*lisaHeight)/lisaWidth;
|
88 |
7589635e
|
Leszek Koltunski
|
float factor = (float)width/lisaWidth;
|
89 |
|
|
|
90 |
f988589e
|
Leszek Koltunski
|
mLisa.move( new Static3D(0,(height-h)/2,0) );
|
91 |
|
|
mLisa.scale(factor);
|
92 |
427ab7bf
|
Leszek Koltunski
|
}
|
93 |
|
|
|
94 |
|
|
Distorted.onSurfaceChanged(width, height);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
100 |
|
|
{
|
101 |
|
|
InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.monalisa);
|
102 |
|
|
InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.fbo);
|
103 |
|
|
|
104 |
|
|
Bitmap bitmap1, bitmap2;
|
105 |
|
|
|
106 |
|
|
try
|
107 |
|
|
{
|
108 |
|
|
bitmap1 = BitmapFactory.decodeStream(is1);
|
109 |
|
|
bitmap2 = BitmapFactory.decodeStream(is2);
|
110 |
|
|
}
|
111 |
|
|
finally
|
112 |
|
|
{
|
113 |
|
|
try
|
114 |
|
|
{
|
115 |
|
|
is1.close();
|
116 |
|
|
is2.close();
|
117 |
|
|
}
|
118 |
|
|
catch(IOException e) { }
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
lisaHeight = bitmap1.getHeight();
|
122 |
|
|
lisaWidth = bitmap1.getWidth();
|
123 |
|
|
|
124 |
|
|
mLisa = new DistortedBitmap(bitmap1, 20);
|
125 |
|
|
mText = new DistortedBitmap(bitmap2, 20);
|
126 |
|
|
|
127 |
|
|
mRoot = new DistortedNode(mLisa);
|
128 |
|
|
mRoot.attach(mText);
|
129 |
|
|
|
130 |
|
|
int textWidth = mText.getWidth();
|
131 |
|
|
int textHeight = mText.getHeight();
|
132 |
7589635e
|
Leszek Koltunski
|
|
133 |
|
|
float factor = lisaWidth/(1.5f*textWidth);
|
134 |
|
|
|
135 |
|
|
mText.move( new Static3D(lisaWidth/6,lisaHeight/3,0) );
|
136 |
f988589e
|
Leszek Koltunski
|
mText.scale(factor);
|
137 |
7bf107f7
|
Leszek Koltunski
|
|
138 |
f988589e
|
Leszek Koltunski
|
Dynamic1D sinkDyn = new Dynamic1D(5000,0.0f);
|
139 |
7bf107f7
|
Leszek Koltunski
|
sinkDyn.add(new Static1D(1.0f));
|
140 |
|
|
sinkDyn.add(new Static1D(0.5f));
|
141 |
|
|
|
142 |
|
|
mText.sink(sinkDyn, new Static2D(textWidth/2,textHeight/2));
|
143 |
59759251
|
Leszek Koltunski
|
|
144 |
f988589e
|
Leszek Koltunski
|
Dynamic1D macroblockDyn = new Dynamic1D(10000,0.0f);
|
145 |
59759251
|
Leszek Koltunski
|
macroblockDyn.add(new Static1D(1));
|
146 |
|
|
macroblockDyn.add(new Static1D(5));
|
147 |
|
|
|
148 |
|
|
mLisa.macroblock(macroblockDyn);
|
149 |
427ab7bf
|
Leszek Koltunski
|
|
150 |
|
|
try
|
151 |
|
|
{
|
152 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
153 |
427ab7bf
|
Leszek Koltunski
|
}
|
154 |
|
|
catch(Exception ex)
|
155 |
|
|
{
|
156 |
|
|
android.util.Log.e("MonaLisa", ex.getMessage() );
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
}
|