1
|
|
2
|
package org.distorted.examples.fbo;
|
3
|
|
4
|
import java.io.IOException;
|
5
|
import java.io.InputStream;
|
6
|
|
7
|
import javax.microedition.khronos.egl.EGLConfig;
|
8
|
import javax.microedition.khronos.opengles.GL10;
|
9
|
|
10
|
import org.distorted.examples.R;
|
11
|
|
12
|
import org.distorted.library.DistortedNode;
|
13
|
import org.distorted.library.Distorted;
|
14
|
import org.distorted.library.DistortedBitmap;
|
15
|
import org.distorted.library.EffectTypes;
|
16
|
import org.distorted.library.Float2D;
|
17
|
|
18
|
import android.graphics.Bitmap;
|
19
|
import android.graphics.BitmapFactory;
|
20
|
import android.opengl.GLES20;
|
21
|
import android.opengl.GLSurfaceView;
|
22
|
|
23
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24
|
|
25
|
class FBORenderer implements GLSurfaceView.Renderer
|
26
|
{
|
27
|
private GLSurfaceView mView;
|
28
|
private DistortedBitmap mLisa, mText;
|
29
|
private int lisaHeight, lisaWidth;
|
30
|
|
31
|
private DistortedNode mRoot;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public FBORenderer(GLSurfaceView v)
|
36
|
{
|
37
|
mView = v;
|
38
|
}
|
39
|
|
40
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
|
42
|
public void onDrawFrame(GL10 glUnused)
|
43
|
{
|
44
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
45
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
46
|
|
47
|
mRoot.draw(System.currentTimeMillis());
|
48
|
}
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
|
52
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
53
|
{
|
54
|
mLisa.abortEffects(EffectTypes.MATRIX);
|
55
|
|
56
|
if( lisaHeight/lisaWidth > height/width )
|
57
|
{
|
58
|
int w = (height*lisaWidth)/lisaHeight;
|
59
|
mLisa.move((width-w)/2 ,0, 0);
|
60
|
mLisa.scale((float)height/lisaHeight);
|
61
|
}
|
62
|
else
|
63
|
{
|
64
|
int h = (width*lisaHeight)/lisaWidth;
|
65
|
mLisa.move(0 ,(height-h)/2, 0);
|
66
|
mLisa.scale((float)width/lisaWidth);
|
67
|
}
|
68
|
|
69
|
Distorted.onSurfaceChanged(width, height);
|
70
|
}
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
|
74
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
75
|
{
|
76
|
InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.monalisa);
|
77
|
InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.fbo);
|
78
|
|
79
|
Bitmap bitmap1, bitmap2;
|
80
|
|
81
|
try
|
82
|
{
|
83
|
bitmap1 = BitmapFactory.decodeStream(is1);
|
84
|
bitmap2 = BitmapFactory.decodeStream(is2);
|
85
|
}
|
86
|
finally
|
87
|
{
|
88
|
try
|
89
|
{
|
90
|
is1.close();
|
91
|
is2.close();
|
92
|
}
|
93
|
catch(IOException e) { }
|
94
|
}
|
95
|
|
96
|
lisaHeight = bitmap1.getHeight();
|
97
|
lisaWidth = bitmap1.getWidth();
|
98
|
|
99
|
mLisa = new DistortedBitmap(bitmap1, 20);
|
100
|
mText = new DistortedBitmap(bitmap2, 20);
|
101
|
|
102
|
mRoot = new DistortedNode(mLisa);
|
103
|
mRoot.attach(mText);
|
104
|
|
105
|
int textWidth = mText.getWidth();
|
106
|
int textHeight = mText.getHeight();
|
107
|
|
108
|
mText.move(lisaWidth/6 , lisaHeight/3, 0);
|
109
|
mText.scale(lisaWidth/(1.5f*textWidth));
|
110
|
mText.sink(0.5f, new Float2D( textWidth/2, textHeight/2), 5000, 0.0f);
|
111
|
mLisa.macroblock(4, 10000, 0.0f);
|
112
|
|
113
|
try
|
114
|
{
|
115
|
Distorted.onSurfaceCreated(mView.getContext());
|
116
|
}
|
117
|
catch(Exception ex)
|
118
|
{
|
119
|
android.util.Log.e("MonaLisa", ex.getMessage() );
|
120
|
}
|
121
|
}
|
122
|
}
|