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 |
758303a3
|
Leszek Koltunski
|
package org.distorted.examples.effectqueue;
|
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 |
10b7e588
|
Leszek Koltunski
|
import org.distorted.library.GridFlat;
|
33 |
e8b6aa95
|
Leszek Koltunski
|
import org.distorted.library.DistortedObject;
|
34 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
35 |
c5a28eb8
|
Leszek Koltunski
|
import org.distorted.library.EffectNames;
|
36 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
37 |
af225332
|
Leszek Koltunski
|
import org.distorted.library.message.EffectListener;
|
38 |
|
|
import org.distorted.library.message.EffectMessage;
|
39 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
40 |
427ab7bf
|
Leszek Koltunski
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
758303a3
|
Leszek Koltunski
|
public class EffectQueueRenderer implements GLSurfaceView.Renderer, EffectListener
|
44 |
bc0a685b
|
Leszek Koltunski
|
{
|
45 |
3f07bedc
|
Leszek Koltunski
|
private static final int NUMLINES = 10;
|
46 |
|
|
static final int BWID = 300;
|
47 |
|
|
static final int BHEI = 400;
|
48 |
427ab7bf
|
Leszek Koltunski
|
|
49 |
758303a3
|
Leszek Koltunski
|
private EffectQueueSurfaceView mView;
|
50 |
bc0a685b
|
Leszek Koltunski
|
private Paint mPaint;
|
51 |
|
|
private int texWidth, texHeight;
|
52 |
3f07bedc
|
Leszek Koltunski
|
|
53 |
e8b6aa95
|
Leszek Koltunski
|
DistortedObject mBackground;
|
54 |
10b7e588
|
Leszek Koltunski
|
GridFlat mGrid;
|
55 |
3f07bedc
|
Leszek Koltunski
|
|
56 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
758303a3
|
Leszek Koltunski
|
EffectQueueRenderer(EffectQueueSurfaceView v)
|
59 |
bc0a685b
|
Leszek Koltunski
|
{
|
60 |
|
|
mPaint = new Paint();
|
61 |
|
|
mPaint.setAntiAlias(true);
|
62 |
|
|
mPaint.setFakeBoldText(true);
|
63 |
|
|
mPaint.setStyle(Style.FILL);
|
64 |
427ab7bf
|
Leszek Koltunski
|
|
65 |
bc0a685b
|
Leszek Koltunski
|
mView = v;
|
66 |
427ab7bf
|
Leszek Koltunski
|
|
67 |
bc0a685b
|
Leszek Koltunski
|
texWidth = BWID;
|
68 |
|
|
texHeight= BHEI;
|
69 |
e8b6aa95
|
Leszek Koltunski
|
|
70 |
10b7e588
|
Leszek Koltunski
|
mGrid = new GridFlat(80,80*texHeight/texWidth);
|
71 |
e8b6aa95
|
Leszek Koltunski
|
mBackground= new DistortedObject(texWidth,texHeight,1);
|
72 |
|
|
|
73 |
|
|
mBackground.addEventListener(this);
|
74 |
bc0a685b
|
Leszek Koltunski
|
}
|
75 |
427ab7bf
|
Leszek Koltunski
|
|
76 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77 |
|
|
|
78 |
bc0a685b
|
Leszek Koltunski
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
79 |
e8b6aa95
|
Leszek Koltunski
|
{
|
80 |
bc0a685b
|
Leszek Koltunski
|
Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
|
81 |
e8b6aa95
|
Leszek Koltunski
|
Canvas canvas = new Canvas(bitmap);
|
82 |
|
|
|
83 |
bc0a685b
|
Leszek Koltunski
|
mPaint.setColor(0xff008800);
|
84 |
|
|
canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
|
85 |
|
|
mPaint.setColor(0xffffffff);
|
86 |
e8b6aa95
|
Leszek Koltunski
|
|
87 |
bc0a685b
|
Leszek Koltunski
|
for(int i=0; i<=NUMLINES ; i++ )
|
88 |
|
|
{
|
89 |
|
|
canvas.drawRect(texWidth*i/NUMLINES - 1, 0, texWidth*i/NUMLINES + 1, texHeight , mPaint);
|
90 |
e8b6aa95
|
Leszek Koltunski
|
canvas.drawRect( 0, texHeight*i/NUMLINES -1, texWidth , texHeight*i/NUMLINES + 1, mPaint);
|
91 |
bc0a685b
|
Leszek Koltunski
|
}
|
92 |
e8b6aa95
|
Leszek Koltunski
|
mBackground.setTexture(bitmap);
|
93 |
af225332
|
Leszek Koltunski
|
|
94 |
bc0a685b
|
Leszek Koltunski
|
try
|
95 |
|
|
{
|
96 |
|
|
Distorted.onSurfaceCreated(mView.getContext());
|
97 |
|
|
}
|
98 |
|
|
catch(Exception ex)
|
99 |
|
|
{
|
100 |
e8b6aa95
|
Leszek Koltunski
|
android.util.Log.e("EffectQueue", ex.getMessage() );
|
101 |
bc0a685b
|
Leszek Koltunski
|
}
|
102 |
|
|
}
|
103 |
427ab7bf
|
Leszek Koltunski
|
|
104 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105 |
|
|
|
106 |
bc0a685b
|
Leszek Koltunski
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
107 |
|
|
{
|
108 |
|
|
mBackground.abortEffects(EffectTypes.MATRIX);
|
109 |
7589635e
|
Leszek Koltunski
|
mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
|
110 |
bc0a685b
|
Leszek Koltunski
|
Distorted.onSurfaceChanged(width,height);
|
111 |
3f07bedc
|
Leszek Koltunski
|
mView.setScreenSize(width,height);
|
112 |
bc0a685b
|
Leszek Koltunski
|
}
|
113 |
427ab7bf
|
Leszek Koltunski
|
|
114 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
|
116 |
bc0a685b
|
Leszek Koltunski
|
public void onDrawFrame(GL10 glUnused)
|
117 |
|
|
{
|
118 |
|
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
|
119 |
e8b6aa95
|
Leszek Koltunski
|
mBackground.draw(System.currentTimeMillis(), mGrid);
|
120 |
bc0a685b
|
Leszek Koltunski
|
}
|
121 |
af225332
|
Leszek Koltunski
|
|
122 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123 |
c5a28eb8
|
Leszek Koltunski
|
// the library sending messages to us. This is running on a library 'MessageSender' thread.
|
124 |
af225332
|
Leszek Koltunski
|
|
125 |
c5a28eb8
|
Leszek Koltunski
|
public void effectMessage(final EffectMessage em, final long effectID, final EffectNames effectName, final long objectID, final String message)
|
126 |
af225332
|
Leszek Koltunski
|
{
|
127 |
758303a3
|
Leszek Koltunski
|
EffectQueueActivity act = (EffectQueueActivity)mView.getContext();
|
128 |
af225332
|
Leszek Koltunski
|
|
129 |
|
|
switch(em)
|
130 |
|
|
{
|
131 |
|
|
case EFFECT_REMOVED : act.effectRemoved(effectID) ; break;
|
132 |
|
|
case EFFECT_FINISHED: act.effectFinished(effectID); break;
|
133 |
|
|
default : break;
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
bc0a685b
|
Leszek Koltunski
|
}
|