1
|
|
2
|
package org.distorted.examples.check;
|
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.Distorted;
|
13
|
import org.distorted.library.DistortedBitmap;
|
14
|
import org.distorted.library.Float2D;
|
15
|
import org.distorted.library.Float3D;
|
16
|
|
17
|
import android.app.AlertDialog;
|
18
|
import android.content.Context;
|
19
|
import android.content.DialogInterface;
|
20
|
import android.graphics.Bitmap;
|
21
|
import android.graphics.BitmapFactory;
|
22
|
import android.opengl.GLES20;
|
23
|
import android.opengl.GLSurfaceView;
|
24
|
|
25
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26
|
|
27
|
class CheckRenderer implements GLSurfaceView.Renderer
|
28
|
{
|
29
|
private GLSurfaceView mView;
|
30
|
private DistortedBitmap mSuccess;
|
31
|
private Float2D pUp, pDown;
|
32
|
private Float3D vUp, vDown;
|
33
|
|
34
|
private int bmpHeight, bmpWidth;
|
35
|
|
36
|
public static String compilationResult;
|
37
|
public static String compilationTitle;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
public CheckRenderer(GLSurfaceView view)
|
42
|
{
|
43
|
mView = view;
|
44
|
|
45
|
Distorted.setMaxVertex(CheckActivity.getMaxV());
|
46
|
Distorted.setMaxFragment(CheckActivity.getMaxF());
|
47
|
}
|
48
|
|
49
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50
|
|
51
|
public void onDrawFrame(GL10 glUnused)
|
52
|
{
|
53
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
54
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
55
|
|
56
|
mSuccess.draw(System.currentTimeMillis());
|
57
|
}
|
58
|
|
59
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60
|
|
61
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
62
|
{
|
63
|
mSuccess.abortAllEffects(Distorted.TYPE_MATR);
|
64
|
|
65
|
if( bmpHeight/bmpWidth > height/width )
|
66
|
{
|
67
|
int w = (height*bmpWidth)/bmpHeight;
|
68
|
mSuccess.move((width-w)/2 ,0, 0);
|
69
|
mSuccess.scale((float)height/bmpHeight);
|
70
|
}
|
71
|
else
|
72
|
{
|
73
|
int h = (width*bmpHeight)/bmpWidth;
|
74
|
mSuccess.move(0 ,(height-h)/2, 0);
|
75
|
mSuccess.scale((float)width/bmpWidth);
|
76
|
}
|
77
|
|
78
|
Distorted.onSurfaceChanged(width, height);
|
79
|
}
|
80
|
|
81
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82
|
|
83
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
84
|
{
|
85
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.success);
|
86
|
Bitmap bitmap;
|
87
|
|
88
|
try
|
89
|
{
|
90
|
bitmap = BitmapFactory.decodeStream(is);
|
91
|
}
|
92
|
finally
|
93
|
{
|
94
|
try
|
95
|
{
|
96
|
is.close();
|
97
|
}
|
98
|
catch(IOException e) { }
|
99
|
}
|
100
|
|
101
|
bmpHeight = bitmap.getHeight();
|
102
|
bmpWidth = bitmap.getWidth();
|
103
|
|
104
|
pDown = new Float2D(bmpWidth/2, 0);
|
105
|
pUp = new Float2D(bmpWidth/2,bmpHeight);
|
106
|
|
107
|
vUp = new Float3D( 0,+bmpHeight,0);
|
108
|
vDown = new Float3D( 0,-bmpHeight,0);
|
109
|
|
110
|
mSuccess = new DistortedBitmap(bitmap, 30);
|
111
|
mSuccess.deform( vUp, pUp, 2000, 0.0f);
|
112
|
mSuccess.deform(vDown, pDown, 2000, 0.0f);
|
113
|
|
114
|
try
|
115
|
{
|
116
|
Distorted.onSurfaceCreated(mView.getContext());
|
117
|
}
|
118
|
catch(Exception ex)
|
119
|
{
|
120
|
compilationTitle = ex.getClass().getSimpleName();
|
121
|
compilationResult= ex.getMessage();
|
122
|
|
123
|
String ver;
|
124
|
|
125
|
ver = GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION);
|
126
|
compilationResult += "\n\nGLSL version: "+(ver==null ? "null" : ver);
|
127
|
ver = GLES20.glGetString(GLES20.GL_VERSION);
|
128
|
compilationResult += "\nGL version: "+(ver==null ? "null" : ver);
|
129
|
ver = GLES20.glGetString(GLES20.GL_VENDOR);
|
130
|
compilationResult += "\nGL vendor: "+(ver==null ? "null" : ver);
|
131
|
ver = GLES20.glGetString(GLES20.GL_RENDERER);
|
132
|
compilationResult += "\nGL renderer: "+(ver==null ? "null" : ver);
|
133
|
|
134
|
CheckActivity act = (CheckActivity)mView.getContext();
|
135
|
|
136
|
act.runOnUiThread(new Runnable()
|
137
|
{
|
138
|
public void run()
|
139
|
{
|
140
|
Context context = mView.getContext();
|
141
|
|
142
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
143
|
builder.setTitle(compilationTitle);
|
144
|
builder.setMessage(compilationResult);
|
145
|
builder.setCancelable(true);
|
146
|
|
147
|
builder.setOnCancelListener(new DialogInterface.OnCancelListener()
|
148
|
{
|
149
|
@Override
|
150
|
public void onCancel(DialogInterface dialog)
|
151
|
{
|
152
|
((CheckActivity)mView.getContext()).finish();
|
153
|
}
|
154
|
});
|
155
|
|
156
|
AlertDialog alert = builder.create();
|
157
|
alert.show();
|
158
|
}
|
159
|
});
|
160
|
}
|
161
|
}
|
162
|
|
163
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164
|
|
165
|
}
|