1 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.movingeffects;
|
2 |
427ab7bf
|
Leszek Koltunski
|
|
3 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
4 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
5 |
|
|
|
6 |
|
|
import android.graphics.Bitmap;
|
7 |
|
|
import android.graphics.Canvas;
|
8 |
|
|
import android.graphics.Paint;
|
9 |
|
|
import android.graphics.Paint.Style;
|
10 |
|
|
import android.opengl.GLES20;
|
11 |
|
|
import android.opengl.GLSurfaceView;
|
12 |
|
|
|
13 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.DistortedBitmap;
|
14 |
|
|
import org.distorted.library.Distorted;
|
15 |
427ab7bf
|
Leszek Koltunski
|
|
16 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
17 |
|
|
|
18 |
|
|
public class MovingEffectsRenderer implements GLSurfaceView.Renderer
|
19 |
|
|
{
|
20 |
|
|
public static final int NUMLINES = 10;
|
21 |
|
|
public static final int BWID = 300;
|
22 |
|
|
public static final int BHEI = 400;
|
23 |
|
|
|
24 |
|
|
private GLSurfaceView mView;
|
25 |
|
|
public static DistortedBitmap mBackground;
|
26 |
|
|
private Canvas mCanvas;
|
27 |
|
|
private Bitmap mBitmap;
|
28 |
|
|
private Paint mPaint;
|
29 |
|
|
private int texWidth, texHeight;
|
30 |
|
|
|
31 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32 |
|
|
|
33 |
|
|
public MovingEffectsRenderer(GLSurfaceView v)
|
34 |
|
|
{
|
35 |
|
|
mPaint = new Paint();
|
36 |
|
|
mPaint.setAntiAlias(true);
|
37 |
|
|
mPaint.setFakeBoldText(true);
|
38 |
|
|
mPaint.setStyle(Style.FILL);
|
39 |
|
|
|
40 |
|
|
mView = v;
|
41 |
|
|
|
42 |
|
|
texWidth = BWID;
|
43 |
|
|
texHeight= BHEI;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47 |
|
|
|
48 |
|
|
private void drawBackground()
|
49 |
|
|
{
|
50 |
|
|
mPaint.setColor(0xff008800);
|
51 |
|
|
mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
|
52 |
|
|
mPaint.setColor(0xffffffff);
|
53 |
|
|
|
54 |
|
|
for(int i=0; i<=NUMLINES ; i++ )
|
55 |
|
|
{
|
56 |
|
|
mCanvas.drawRect(texWidth*i/NUMLINES - 2, 0, texWidth*i/NUMLINES + 2, texHeight , mPaint);
|
57 |
|
|
mCanvas.drawRect( 0, texHeight*i/NUMLINES -2, texWidth , texHeight*i/NUMLINES + 2, mPaint);
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
64 |
|
|
{
|
65 |
|
|
mBackground = new DistortedBitmap(texWidth,texHeight, 80);
|
66 |
|
|
mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
|
67 |
|
|
mCanvas = new Canvas(mBitmap);
|
68 |
|
|
|
69 |
|
|
try
|
70 |
|
|
{
|
71 |
|
|
Distorted.onSurfaceCreated(mView);
|
72 |
|
|
}
|
73 |
|
|
catch(Exception ex)
|
74 |
|
|
{
|
75 |
|
|
android.util.Log.e("Renderer", ex.getMessage() );
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
|
|
|
81 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
82 |
|
|
{
|
83 |
|
|
mBackground.abortAllEffects(Distorted.TYPE_MATR);
|
84 |
|
|
mBackground.scale((float)width/texWidth,(float)height/texHeight,1);
|
85 |
|
|
|
86 |
|
|
Distorted.onSurfaceChanged(width, height);
|
87 |
|
|
MovingEffectsSurfaceView.setScreenSize(width, height);
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
|
|
public void onDrawFrame(GL10 glUnused)
|
93 |
|
|
{
|
94 |
|
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
|
95 |
|
|
|
96 |
|
|
long time = System.currentTimeMillis();
|
97 |
|
|
|
98 |
|
|
if (MovingEffectsSurfaceView.getCurrentEffect() == MovingEffectsSurfaceView.EFFECT_POINTS )
|
99 |
|
|
{
|
100 |
|
|
drawBackground();
|
101 |
|
|
MovingEffectsSurfaceView.drawCurve(mCanvas,time);
|
102 |
|
|
mBackground.setBitmap(mBitmap);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
mBackground.draw(time);
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
}
|