Project

General

Profile

Download (3.36 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / monalisa / MonaLisaRenderer.java @ 95593730

1

    
2
package org.distorted.examples.monalisa;
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
import org.distorted.library.Distorted;
12
import org.distorted.library.DistortedBitmap;
13
import org.distorted.library.EffectTypes;
14
import org.distorted.library.Float2D;
15
import org.distorted.library.Float3D;
16
import org.distorted.library.Float4D;
17

    
18
import android.graphics.Bitmap;
19
import android.graphics.BitmapFactory;
20
import android.opengl.GLES20;
21
import android.opengl.GLSurfaceView;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

    
25
class MonaLisaRenderer implements GLSurfaceView.Renderer 
26
{
27
    private GLSurfaceView mView;
28
    private DistortedBitmap monaLisa;
29
    private Float2D pLeft, pRight;
30
    private Float4D rLeft, rRight;
31
    private Float3D vLeft, vRight;
32
    private int bmpHeight, bmpWidth;
33
    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
    public MonaLisaRenderer(GLSurfaceView v) 
37
      {
38
      mView = v;
39
      
40
      pLeft = new Float2D( 90, 258);
41
      pRight= new Float2D(176, 255);
42
      
43
      rLeft = new Float4D(-10,-10,25,25);
44
      rRight= new Float4D( 10, -5,25,25);
45
      
46
      vLeft = new Float3D(-20,-20,0);
47
      vRight= new Float3D( 20,-10,0);
48
      }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
   
52
    public void onDrawFrame(GL10 glUnused) 
53
      {
54
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
55
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
56
      
57
      monaLisa.draw(System.currentTimeMillis());
58
      }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
    
62
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
63
      { 
64
      monaLisa.abortAllEffects(EffectTypes.MATRIX.type);
65
         
66
      if( bmpHeight/bmpWidth > height/width )
67
        {
68
        int w = (height*bmpWidth)/bmpHeight;
69
        monaLisa.move((width-w)/2 ,0, 0);
70
        monaLisa.scale((float)height/bmpHeight);
71
        }
72
      else
73
        {
74
        int h = (width*bmpHeight)/bmpWidth;
75
        monaLisa.move(0 ,(height-h)/2, 0);
76
        monaLisa.scale((float)width/bmpWidth);
77
        }
78
      
79
      Distorted.onSurfaceChanged(width, height); 
80
      }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
    
84
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
85
      {
86
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.monalisa);
87
      Bitmap bitmap;
88
        
89
      try 
90
        {
91
        bitmap = BitmapFactory.decodeStream(is);
92
        } 
93
      finally 
94
        {
95
        try 
96
          {
97
          is.close();
98
          } 
99
        catch(IOException e) { }
100
        }  
101
      
102
      bmpHeight = bitmap.getHeight();
103
      bmpWidth  = bitmap.getWidth();
104
      
105
      monaLisa = new DistortedBitmap(bitmap, 10);
106
      monaLisa.distort( vLeft, rLeft , pLeft, 1000, 0);
107
      monaLisa.distort(vRight, rRight, pRight,1000, 0);
108
      
109
      try
110
        {
111
        Distorted.onSurfaceCreated(mView.getContext());
112
        }
113
      catch(Exception ex)
114
        {
115
        android.util.Log.e("MonaLisa", ex.getMessage() );
116
        }
117
      }
118
}
(2-2/3)