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 |
427ab7bf
|
Leszek Koltunski
|
|
20 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.check;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
22 |
|
|
import java.io.IOException;
|
23 |
|
|
import java.io.InputStream;
|
24 |
|
|
|
25 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
26 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
27 |
|
|
|
28 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.examples.R;
|
29 |
427ab7bf
|
Leszek Koltunski
|
|
30 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
31 |
|
|
import org.distorted.library.DistortedBitmap;
|
32 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
33 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static1D;
|
34 |
|
|
import org.distorted.library.type.Static2D;
|
35 |
|
|
import org.distorted.library.type.Static3D;
|
36 |
|
|
import org.distorted.library.type.Static4D;
|
37 |
|
|
import org.distorted.library.type.Dynamic1D;
|
38 |
|
|
import org.distorted.library.type.Dynamic2D;
|
39 |
427ab7bf
|
Leszek Koltunski
|
|
40 |
|
|
import android.app.AlertDialog;
|
41 |
|
|
import android.content.Context;
|
42 |
|
|
import android.content.DialogInterface;
|
43 |
|
|
import android.graphics.Bitmap;
|
44 |
|
|
import android.graphics.BitmapFactory;
|
45 |
|
|
import android.opengl.GLES20;
|
46 |
|
|
import android.opengl.GLSurfaceView;
|
47 |
|
|
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49 |
|
|
|
50 |
|
|
class CheckRenderer implements GLSurfaceView.Renderer
|
51 |
|
|
{
|
52 |
|
|
private GLSurfaceView mView;
|
53 |
|
|
private DistortedBitmap mSuccess;
|
54 |
|
|
private int bmpHeight, bmpWidth;
|
55 |
9c5b5cb6
|
Leszek Koltunski
|
|
56 |
427ab7bf
|
Leszek Koltunski
|
public static String compilationResult;
|
57 |
|
|
public static String compilationTitle;
|
58 |
9c5b5cb6
|
Leszek Koltunski
|
|
59 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60 |
|
|
|
61 |
|
|
public CheckRenderer(GLSurfaceView view)
|
62 |
|
|
{
|
63 |
|
|
mView = view;
|
64 |
9c5b5cb6
|
Leszek Koltunski
|
|
65 |
427ab7bf
|
Leszek Koltunski
|
Distorted.setMaxVertex(CheckActivity.getMaxV());
|
66 |
|
|
Distorted.setMaxFragment(CheckActivity.getMaxF());
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
public void onDrawFrame(GL10 glUnused)
|
72 |
|
|
{
|
73 |
|
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
74 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
75 |
|
|
|
76 |
|
|
mSuccess.draw(System.currentTimeMillis());
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
|
|
|
81 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
82 |
|
|
{
|
83 |
a8c3ada7
|
Leszek Koltunski
|
mSuccess.abortEffects(EffectTypes.MATRIX);
|
84 |
427ab7bf
|
Leszek Koltunski
|
|
85 |
|
|
if( bmpHeight/bmpWidth > height/width )
|
86 |
|
|
{
|
87 |
|
|
int w = (height*bmpWidth)/bmpHeight;
|
88 |
7589635e
|
Leszek Koltunski
|
float factor = (float)height/bmpHeight;
|
89 |
|
|
|
90 |
|
|
mSuccess.move( new Static3D((width-w)/2,0,0) );
|
91 |
|
|
mSuccess.scale( new Static3D(factor,factor,factor) );
|
92 |
427ab7bf
|
Leszek Koltunski
|
}
|
93 |
|
|
else
|
94 |
|
|
{
|
95 |
|
|
int h = (width*bmpHeight)/bmpWidth;
|
96 |
7589635e
|
Leszek Koltunski
|
float factor = (float)width/bmpWidth;
|
97 |
|
|
|
98 |
|
|
mSuccess.move( new Static3D(0,(height-h)/2,0) );
|
99 |
|
|
mSuccess.scale( new Static3D(factor,factor,factor) );
|
100 |
427ab7bf
|
Leszek Koltunski
|
}
|
101 |
|
|
|
102 |
|
|
Distorted.onSurfaceChanged(width, height);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
|
107 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
108 |
|
|
{
|
109 |
|
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.success);
|
110 |
|
|
Bitmap bitmap;
|
111 |
9c5b5cb6
|
Leszek Koltunski
|
|
112 |
|
|
try
|
113 |
427ab7bf
|
Leszek Koltunski
|
{
|
114 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
115 |
|
|
}
|
116 |
|
|
finally
|
117 |
|
|
{
|
118 |
|
|
try
|
119 |
|
|
{
|
120 |
|
|
is.close();
|
121 |
|
|
}
|
122 |
|
|
catch(IOException e) { }
|
123 |
9c5b5cb6
|
Leszek Koltunski
|
}
|
124 |
|
|
|
125 |
|
|
mSuccess = new DistortedBitmap(bitmap, 30);
|
126 |
|
|
|
127 |
427ab7bf
|
Leszek Koltunski
|
bmpHeight = bitmap.getHeight();
|
128 |
|
|
bmpWidth = bitmap.getWidth();
|
129 |
9c5b5cb6
|
Leszek Koltunski
|
|
130 |
|
|
// Try adding 2 Vertex Effects to the Bitmap.
|
131 |
|
|
// This will fail if we have set maxVertexEffects to something < 2.
|
132 |
|
|
//
|
133 |
|
|
// Even if adding some of the Effects fails, the App will still start - you just won't see
|
134 |
|
|
// the effects that failed to add.
|
135 |
7589635e
|
Leszek Koltunski
|
Static2D pDown = new Static2D(bmpWidth/2, 0);
|
136 |
|
|
Static3D vDown = new Static3D( 0,-bmpHeight,0);
|
137 |
|
|
Static4D mRegion = new Static4D( 0, 0, 40 ,40 );
|
138 |
9c5b5cb6
|
Leszek Koltunski
|
|
139 |
7589635e
|
Leszek Koltunski
|
Dynamic2D mPoint = new Dynamic2D();
|
140 |
9c5b5cb6
|
Leszek Koltunski
|
mPoint.setCount(0.0f);
|
141 |
|
|
mPoint.setDuration(2000);
|
142 |
7589635e
|
Leszek Koltunski
|
mPoint.add(new Static2D( 0, bmpHeight/2));
|
143 |
|
|
mPoint.add(new Static2D( bmpWidth, bmpHeight/2));
|
144 |
9c5b5cb6
|
Leszek Koltunski
|
|
145 |
|
|
mSuccess.swirl( 30, mRegion, mPoint );
|
146 |
427ab7bf
|
Leszek Koltunski
|
mSuccess.deform(vDown, pDown, 2000, 0.0f);
|
147 |
9c5b5cb6
|
Leszek Koltunski
|
|
148 |
|
|
// Now try adding 1 Fragment Effect. Likewise, will fail if maxFragmentEffects is <1.
|
149 |
7589635e
|
Leszek Koltunski
|
Static3D color = new Static3D(1,0,0);
|
150 |
|
|
Dynamic1D inter = new Dynamic1D();
|
151 |
9c5b5cb6
|
Leszek Koltunski
|
inter.setCount(0.0f);
|
152 |
|
|
inter.setDuration(2000);
|
153 |
7589635e
|
Leszek Koltunski
|
inter.add(new Static1D(0));
|
154 |
|
|
inter.add(new Static1D(1));
|
155 |
9c5b5cb6
|
Leszek Koltunski
|
|
156 |
7589635e
|
Leszek Koltunski
|
mSuccess.chroma(inter, color, null, new Static2D(0,0) );
|
157 |
9c5b5cb6
|
Leszek Koltunski
|
|
158 |
427ab7bf
|
Leszek Koltunski
|
try
|
159 |
|
|
{
|
160 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
161 |
427ab7bf
|
Leszek Koltunski
|
}
|
162 |
|
|
catch(Exception ex)
|
163 |
|
|
{
|
164 |
9c5b5cb6
|
Leszek Koltunski
|
// We have failed to compile or link shaders - probably too many effects.
|
165 |
|
|
// (each effect adds a certain number of Uniforms to the shader and there
|
166 |
|
|
// can only be a limited number of those )
|
167 |
|
|
|
168 |
427ab7bf
|
Leszek Koltunski
|
compilationTitle = ex.getClass().getSimpleName();
|
169 |
|
|
compilationResult= ex.getMessage();
|
170 |
|
|
|
171 |
|
|
String ver;
|
172 |
|
|
|
173 |
|
|
ver = GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION);
|
174 |
|
|
compilationResult += "\n\nGLSL version: "+(ver==null ? "null" : ver);
|
175 |
|
|
ver = GLES20.glGetString(GLES20.GL_VERSION);
|
176 |
|
|
compilationResult += "\nGL version: "+(ver==null ? "null" : ver);
|
177 |
|
|
ver = GLES20.glGetString(GLES20.GL_VENDOR);
|
178 |
|
|
compilationResult += "\nGL vendor: "+(ver==null ? "null" : ver);
|
179 |
|
|
ver = GLES20.glGetString(GLES20.GL_RENDERER);
|
180 |
|
|
compilationResult += "\nGL renderer: "+(ver==null ? "null" : ver);
|
181 |
|
|
|
182 |
|
|
CheckActivity act = (CheckActivity)mView.getContext();
|
183 |
|
|
|
184 |
|
|
act.runOnUiThread(new Runnable()
|
185 |
|
|
{
|
186 |
|
|
public void run()
|
187 |
|
|
{
|
188 |
|
|
Context context = mView.getContext();
|
189 |
|
|
|
190 |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
191 |
|
|
builder.setTitle(compilationTitle);
|
192 |
|
|
builder.setMessage(compilationResult);
|
193 |
|
|
builder.setCancelable(true);
|
194 |
|
|
|
195 |
|
|
builder.setOnCancelListener(new DialogInterface.OnCancelListener()
|
196 |
|
|
{
|
197 |
|
|
@Override
|
198 |
|
|
public void onCancel(DialogInterface dialog)
|
199 |
|
|
{
|
200 |
|
|
((CheckActivity)mView.getContext()).finish();
|
201 |
|
|
}
|
202 |
|
|
});
|
203 |
|
|
|
204 |
|
|
AlertDialog alert = builder.create();
|
205 |
|
|
alert.show();
|
206 |
|
|
}
|
207 |
|
|
});
|
208 |
|
|
}
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
212 |
|
|
|
213 |
|
|
}
|