1 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.scratchpad;
|
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 ScratchpadRenderer 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 Paint mPaint;
|
27 |
|
|
private int texWidth, texHeight;
|
28 |
|
|
|
29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
|
31 |
|
|
public ScratchpadRenderer(GLSurfaceView v)
|
32 |
|
|
{
|
33 |
|
|
mPaint = new Paint();
|
34 |
|
|
mPaint.setAntiAlias(true);
|
35 |
|
|
mPaint.setFakeBoldText(true);
|
36 |
|
|
mPaint.setStyle(Style.FILL);
|
37 |
|
|
|
38 |
|
|
mView = v;
|
39 |
|
|
|
40 |
|
|
texWidth = BWID;
|
41 |
|
|
texHeight= BHEI;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
47 |
|
|
{
|
48 |
|
|
mBackground = new DistortedBitmap(texWidth,texHeight, 80);
|
49 |
|
|
Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
|
50 |
|
|
Canvas canvas = new Canvas(bitmap);
|
51 |
|
|
|
52 |
|
|
mPaint.setColor(0xff008800);
|
53 |
|
|
canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
|
54 |
|
|
mPaint.setColor(0xffffffff);
|
55 |
|
|
|
56 |
|
|
for(int i=0; i<=NUMLINES ; i++ )
|
57 |
|
|
{
|
58 |
|
|
canvas.drawRect(texWidth*i/NUMLINES - 1, 0, texWidth*i/NUMLINES + 1, texHeight , mPaint);
|
59 |
|
|
canvas.drawRect( 0, texHeight*i/NUMLINES -1, texWidth , texHeight*i/NUMLINES + 1, mPaint);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
mBackground.setBitmap(bitmap);
|
63 |
|
|
|
64 |
|
|
try
|
65 |
|
|
{
|
66 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
67 |
427ab7bf
|
Leszek Koltunski
|
}
|
68 |
|
|
catch(Exception ex)
|
69 |
|
|
{
|
70 |
ed1c0b33
|
Leszek Koltunski
|
android.util.Log.e("Scratchpad", ex.getMessage() );
|
71 |
427ab7bf
|
Leszek Koltunski
|
}
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
|
|
76 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
77 |
|
|
{
|
78 |
89a0d841
|
Leszek Koltunski
|
mBackground.abortAllEffects(Distorted.TYPE_PRE);
|
79 |
427ab7bf
|
Leszek Koltunski
|
mBackground.scale((float)width/texWidth,(float)height/texHeight,1);
|
80 |
|
|
Distorted.onSurfaceChanged(width,height);
|
81 |
|
|
ScratchpadSurfaceView.setScreenSize(width,height);
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
|
|
public void onDrawFrame(GL10 glUnused)
|
87 |
|
|
{
|
88 |
|
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
|
89 |
|
|
mBackground.draw(System.currentTimeMillis());
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93 |
|
|
}
|