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 |
|
|
|
20 |
e5424523
|
Leszek Koltunski
|
package org.distorted.examples.effects2d;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
22 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
23 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
24 |
|
|
|
25 |
|
|
import android.graphics.Bitmap;
|
26 |
|
|
import android.graphics.Canvas;
|
27 |
|
|
import android.graphics.Paint;
|
28 |
|
|
import android.graphics.Paint.Style;
|
29 |
|
|
import android.opengl.GLES20;
|
30 |
|
|
import android.opengl.GLSurfaceView;
|
31 |
|
|
|
32 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.DistortedBitmap;
|
33 |
|
|
import org.distorted.library.Distorted;
|
34 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
35 |
af225332
|
Leszek Koltunski
|
import org.distorted.library.message.EffectListener;
|
36 |
|
|
import org.distorted.library.message.EffectMessage;
|
37 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
38 |
427ab7bf
|
Leszek Koltunski
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
af225332
|
Leszek Koltunski
|
public class Effects2DRenderer implements GLSurfaceView.Renderer, EffectListener
|
42 |
bc0a685b
|
Leszek Koltunski
|
{
|
43 |
|
|
public static final int NUMLINES = 10;
|
44 |
|
|
public static final int BWID = 300;
|
45 |
|
|
public static final int BHEI = 400;
|
46 |
427ab7bf
|
Leszek Koltunski
|
|
47 |
bc0a685b
|
Leszek Koltunski
|
private GLSurfaceView mView;
|
48 |
|
|
public static DistortedBitmap mBackground;
|
49 |
|
|
private Paint mPaint;
|
50 |
|
|
private int texWidth, texHeight;
|
51 |
427ab7bf
|
Leszek Koltunski
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
e5424523
|
Leszek Koltunski
|
public Effects2DRenderer(GLSurfaceView v)
|
55 |
bc0a685b
|
Leszek Koltunski
|
{
|
56 |
|
|
mPaint = new Paint();
|
57 |
|
|
mPaint.setAntiAlias(true);
|
58 |
|
|
mPaint.setFakeBoldText(true);
|
59 |
|
|
mPaint.setStyle(Style.FILL);
|
60 |
427ab7bf
|
Leszek Koltunski
|
|
61 |
bc0a685b
|
Leszek Koltunski
|
mView = v;
|
62 |
427ab7bf
|
Leszek Koltunski
|
|
63 |
bc0a685b
|
Leszek Koltunski
|
texWidth = BWID;
|
64 |
|
|
texHeight= BHEI;
|
65 |
|
|
}
|
66 |
427ab7bf
|
Leszek Koltunski
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
|
69 |
bc0a685b
|
Leszek Koltunski
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
70 |
|
|
{
|
71 |
|
|
mBackground = new DistortedBitmap(texWidth,texHeight, 80);
|
72 |
|
|
Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
|
73 |
|
|
Canvas canvas = new Canvas(bitmap);
|
74 |
427ab7bf
|
Leszek Koltunski
|
|
75 |
bc0a685b
|
Leszek Koltunski
|
mPaint.setColor(0xff008800);
|
76 |
|
|
canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
|
77 |
|
|
mPaint.setColor(0xffffffff);
|
78 |
427ab7bf
|
Leszek Koltunski
|
|
79 |
bc0a685b
|
Leszek Koltunski
|
for(int i=0; i<=NUMLINES ; i++ )
|
80 |
|
|
{
|
81 |
|
|
canvas.drawRect(texWidth*i/NUMLINES - 1, 0, texWidth*i/NUMLINES + 1, texHeight , mPaint);
|
82 |
|
|
canvas.drawRect( 0, texHeight*i/NUMLINES -1, texWidth , texHeight*i/NUMLINES + 1, mPaint);
|
83 |
|
|
}
|
84 |
427ab7bf
|
Leszek Koltunski
|
|
85 |
bc0a685b
|
Leszek Koltunski
|
mBackground.setBitmap(bitmap);
|
86 |
af225332
|
Leszek Koltunski
|
mBackground.addEventListener(this);
|
87 |
|
|
|
88 |
bc0a685b
|
Leszek Koltunski
|
try
|
89 |
|
|
{
|
90 |
|
|
Distorted.onSurfaceCreated(mView.getContext());
|
91 |
|
|
}
|
92 |
|
|
catch(Exception ex)
|
93 |
|
|
{
|
94 |
|
|
android.util.Log.e("Scratchpad", ex.getMessage() );
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
427ab7bf
|
Leszek Koltunski
|
|
98 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
99 |
|
|
|
100 |
bc0a685b
|
Leszek Koltunski
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
101 |
|
|
{
|
102 |
|
|
mBackground.abortEffects(EffectTypes.MATRIX);
|
103 |
7589635e
|
Leszek Koltunski
|
mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
|
104 |
bc0a685b
|
Leszek Koltunski
|
Distorted.onSurfaceChanged(width,height);
|
105 |
e5424523
|
Leszek Koltunski
|
Effects2DSurfaceView.setScreenSize(width,height);
|
106 |
bc0a685b
|
Leszek Koltunski
|
}
|
107 |
427ab7bf
|
Leszek Koltunski
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
bc0a685b
|
Leszek Koltunski
|
public void onDrawFrame(GL10 glUnused)
|
111 |
|
|
{
|
112 |
|
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
|
113 |
|
|
mBackground.draw(System.currentTimeMillis());
|
114 |
|
|
}
|
115 |
af225332
|
Leszek Koltunski
|
|
116 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
|
|
// the library sending messages to us
|
118 |
|
|
|
119 |
|
|
public void effectMessage(final EffectMessage em, final long effectID, final int effectName, final long bitmapID, final String message)
|
120 |
|
|
{
|
121 |
|
|
Effects2DActivity act = (Effects2DActivity)mView.getContext();
|
122 |
|
|
|
123 |
|
|
switch(em)
|
124 |
|
|
{
|
125 |
|
|
case EFFECT_REMOVED : act.effectRemoved(effectID) ; break;
|
126 |
|
|
case EFFECT_FINISHED: act.effectFinished(effectID); break;
|
127 |
|
|
default : break;
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
bc0a685b
|
Leszek Koltunski
|
}
|