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/girl/GirlRenderer.java
27 27

  
28 28
import org.distorted.examples.R;
29 29

  
30
import org.distorted.library.effect.EffectType;
31 30
import org.distorted.library.effect.MatrixEffectScale;
32 31
import org.distorted.library.effect.VertexEffectDistort;
33 32
import org.distorted.library.effect.VertexEffectScale;
......
44 43
import org.distorted.library.type.Static3D;
45 44
import org.distorted.library.type.Static4D;
46 45

  
46
import android.app.ActivityManager;
47
import android.content.Context;
48
import android.content.pm.ConfigurationInfo;
49
import android.content.res.Resources;
47 50
import android.graphics.Bitmap;
48 51
import android.graphics.BitmapFactory;
49 52
import android.opengl.GLSurfaceView;
50 53

  
51 54
///////////////////////////////////////////////////////////////////////////////////////////////////
52 55

  
53
class GirlRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
56
class GirlRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
54 57
{
55
    private GLSurfaceView mView;
56
    private DistortedEffects mEffects;
57
    private DistortedScreen mScreen;
58
    private DistortedTexture mTexture;
58
    private final GLSurfaceView mView;
59
    private final Resources mResources;
60
    private final DistortedEffects mEffects;
61
    private final DistortedScreen mScreen;
62
    private final DistortedTexture mTexture;
63
    private final Static3D v0,v1,v2,v3;
64
    private final Static1D dBegin, dMiddle, dEnd, s0;
65
    private final Static3D mScaleMatrix, mScaleVertex;
66

  
59 67
    private MeshSquare mMesh;
60
    private Static3D v0,v1,v2,v3;
61
    private Static1D dBegin, dMiddle, dEnd, s0;
62
    private Static3D mScaleMatrix, mScaleVertex;
63 68
    private float mBmpRatio;
64 69

  
65 70
///////////////////////////////////////////////////////////////////////////////////////////////////
......
68 73
   GirlRenderer(GLSurfaceView v)
69 74
      {
70 75
      mView = v;
76
      mResources = v.getResources();
71 77

  
72 78
      Static3D pLeft = new Static3D(-68/400.0f, 36/400.0f, 0);
73 79
      Static3D pRight= new Static3D( 47/400.0f, 36/400.0f, 0);
......
192 198
         {
193 199
         is.close();
194 200
         }
195
       catch(IOException e) { }
201
       catch(IOException ignored) { }
196 202
       }
197 203
      
198 204
     mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
......
210 216
     VertexEffectSink.enable();
211 217
     VertexEffectSwirl.enable();
212 218

  
213
     DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
219
     DistortedLibrary.onSurfaceCreated(this);
214 220
     }
215 221

  
216 222
///////////////////////////////////////////////////////////////////////////////////////////////////
......
219 225
     {
220 226
     android.util.Log.e("Girl", ex.getMessage() );
221 227
     }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

  
231
   public int openGlVersion()
232
      {
233
      Context context = mView.getContext();
234
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
235
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
236
      int glESversion = configurationInfo.reqGlEsVersion;
237
      int major = glESversion >> 16;
238
      int minor = glESversion & 0xff;
239

  
240
      return 100*major + 10*minor;
241
      }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
   public InputStream localFile(int fileID)
246
      {
247
      return mResources.openRawResource(fileID);
248
      }
249

  
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

  
252
   public void logMessage(String message)
253
      {
254
      android.util.Log.e("Girl", message );
255
      }
222 256
}

Also available in: Unified diff