Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/catanddog/CatAndDogRenderer.java | ||
---|---|---|
42 | 42 |
import org.distorted.library.type.Static1D; |
43 | 43 |
import org.distorted.library.type.Static3D; |
44 | 44 |
|
45 |
import android.app.ActivityManager; |
|
46 |
import android.content.Context; |
|
47 |
import android.content.pm.ConfigurationInfo; |
|
48 |
import android.content.res.Resources; |
|
45 | 49 |
import android.graphics.Bitmap; |
46 | 50 |
import android.graphics.BitmapFactory; |
47 | 51 |
import android.opengl.GLSurfaceView; |
48 | 52 |
|
49 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
50 | 54 |
|
51 |
class CatAndDogRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
55 |
class CatAndDogRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
52 | 56 |
{ |
53 |
private GLSurfaceView mView; |
|
54 |
private DistortedTexture mTexture; |
|
55 |
private DistortedScreen mScreen; |
|
56 |
private Static3D mScaleStart, mScaleEnd, mMoveStart, mMoveEnd; |
|
57 |
private final GLSurfaceView mView; |
|
58 |
private final Resources mResources; |
|
59 |
private final DistortedTexture mTexture; |
|
60 |
private final DistortedScreen mScreen; |
|
61 |
private final Static3D mScaleStart, mScaleEnd, mMoveStart, mMoveEnd; |
|
62 |
|
|
57 | 63 |
private float mBmpRatio; |
58 | 64 |
|
59 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
64 | 70 |
final int DURATION_MATRIX_EFFECTS = 10000; |
65 | 71 |
|
66 | 72 |
mView = v; |
73 |
mResources = v.getResources(); |
|
67 | 74 |
|
68 | 75 |
DistortedEffects effects = new DistortedEffects(); |
69 | 76 |
|
... | ... | |
114 | 121 |
{ |
115 | 122 |
final float SCALE_START = 0.3f; |
116 | 123 |
final float SCALE_END = 0.6f; |
117 |
float min= (width>height ? height : width);
|
|
124 |
float min= (Math.min(width,height));
|
|
118 | 125 |
|
119 | 126 |
mScaleStart.set( SCALE_START*min, SCALE_START*min*mBmpRatio, 1 ); |
120 | 127 |
mScaleEnd .set( SCALE_END *min, SCALE_END *min*mBmpRatio, 1 ); |
... | ... | |
149 | 156 |
{ |
150 | 157 |
is.close(); |
151 | 158 |
} |
152 |
catch(IOException e) { }
|
|
159 |
catch(IOException ignored) { }
|
|
153 | 160 |
} |
154 | 161 |
|
155 | 162 |
mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth(); |
... | ... | |
158 | 165 |
FragmentEffectChroma.enable(); |
159 | 166 |
FragmentEffectAlpha.enable(); |
160 | 167 |
|
161 |
DistortedLibrary.onSurfaceCreated(mView.getContext(),this);
|
|
168 |
DistortedLibrary.onSurfaceCreated(this); |
|
162 | 169 |
} |
163 | 170 |
|
164 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
167 | 174 |
{ |
168 | 175 |
android.util.Log.e("CatAndDog", ex.getMessage() ); |
169 | 176 |
} |
177 |
|
|
178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
179 |
|
|
180 |
public int openGlVersion() |
|
181 |
{ |
|
182 |
Context context = mView.getContext(); |
|
183 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
184 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
185 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
186 |
int major = glESversion >> 16; |
|
187 |
int minor = glESversion & 0xff; |
|
188 |
|
|
189 |
return 100*major + 10*minor; |
|
190 |
} |
|
191 |
|
|
192 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
193 |
|
|
194 |
public InputStream localFile(int fileID) |
|
195 |
{ |
|
196 |
return mResources.openRawResource(fileID); |
|
197 |
} |
|
198 |
|
|
199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
200 |
|
|
201 |
public void logMessage(String message) |
|
202 |
{ |
|
203 |
android.util.Log.e("CatAndDog", message ); |
|
204 |
} |
|
170 | 205 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.