Project

General

Profile

« Previous | Next » 

Revision dc10a48d

Added by Leszek Koltunski about 1 year ago

Decouple (to a large degree) the OpenGL Library from Android.

View differences:

src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
42 42
import org.distorted.library.type.Static3D;
43 43
import org.distorted.library.type.Static4D;
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 DifferentBitmapsRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
55
class DifferentBitmapsRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
52 56
{
53 57
   private static final int[] bitmap = { R.raw.dog, R.raw.face, R.raw.cat };
54 58
   private static final int NUM = bitmap.length;
55 59
   
56
   private GLSurfaceView mView;
57
   private DistortedEffects[] mEffects;
60
   private final GLSurfaceView mView;
61
   private final DistortedEffects[] mEffects;
62
   private final DistortedScreen mScreen;
63
   private final Static3D mScaleMatrix, mScaleVertex;
64
   private final Static3D[] mMove;
65
   private final Resources mResources;
58 66
   private DistortedTexture[] mTexture;
59 67
   private MeshSquare mMesh;
60
   private DistortedScreen mScreen;
61
   private Static3D mScaleMatrix, mScaleVertex;
62
   private Static3D[] mMove;
63 68

  
64 69
///////////////////////////////////////////////////////////////////////////////////////////////////
65 70

  
66 71
   DifferentBitmapsRenderer(GLSurfaceView v)
67 72
      {     
68 73
      mView = v;
69
     
74
      mResources = v.getResources();
75

  
70 76
      Dynamic3D dDistort = new Dynamic3D(3000,0.0f);
71 77
      dDistort.add(new Static3D( 25,0,0));
72 78
      dDistort.add(new Static3D(-25,0,0));
......
168 174
     VertexEffectSink.enable();
169 175
     VertexEffectDistort.enable();
170 176

  
171
     DistortedLibrary.onSurfaceCreated(mView.getContext(),this);
172
     }
173

  
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

  
176
   public void distortedException(Exception ex)
177
     {
178
     android.util.Log.e("DifferentBitmaps", ex.getMessage() );
177
     DistortedLibrary.onSurfaceCreated(this);
179 178
     }
180 179

  
181 180
///////////////////////////////////////////////////////////////////////////////////////////////////
......
195 194
         {
196 195
         is.close();
197 196
         }
198
       catch(IOException e) { }
197
       catch(IOException ignored) { }
199 198
       }
200 199

  
201 200
     return bitmap;
202 201
     }
203 202

  
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

  
205
   public void distortedException(Exception ex)
206
     {
207
     android.util.Log.e("DifferentBitmaps", ex.getMessage() );
208
     }
209

  
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

  
212
   public int openGlVersion()
213
     {
214
     Context context = mView.getContext();
215
     final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
216
     final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
217
     int glESversion = configurationInfo.reqGlEsVersion;
218
     int major = glESversion >> 16;
219
     int minor = glESversion & 0xff;
220

  
221
     return 100*major + 10*minor;
222
     }
223

  
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

  
226
   public InputStream localFile(int fileID)
227
     {
228
     return mResources.openRawResource(fileID);
229
     }
230

  
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

  
233
   public void logMessage(String message)
234
     {
235
     android.util.Log.e("DifferentBitmaps", message );
236
     }
204 237
}

Also available in: Unified diff