Project

General

Profile

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

examples / src / main / java / org / distorted / examples / sink / SinkRenderer.java @ a8c3ada7

1

    
2
package org.distorted.examples.sink;
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

    
12
import org.distorted.library.Distorted;
13
import org.distorted.library.DistortedBitmap;
14
import org.distorted.library.EffectTypes;
15
import org.distorted.library.Float2D;
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 SinkRenderer implements GLSurfaceView.Renderer 
26
{
27
   private GLSurfaceView mView;
28
   private DistortedBitmap sinkBmp;
29
   private Float2D pLeft, pRight;
30
   private Float4D Region;
31
   private int bmpHeight, bmpWidth;
32
    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
   public SinkRenderer(GLSurfaceView v) 
36
      { 
37
      mView = v;
38
      
39
      pLeft = new Float2D(214, 206);
40
      pRight= new Float2D(390, 212);
41
      Region= new Float4D(0,0,60,60);
42
      }
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
   
46
    public void onDrawFrame(GL10 glUnused) 
47
      {
48
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
49
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
50
      
51
      sinkBmp.draw(System.currentTimeMillis());
52
      }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
    
56
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
57
      { 
58
      sinkBmp.abortEffects(EffectTypes.MATRIX);
59
         
60
      if( bmpHeight/bmpWidth > height/width )
61
        {
62
        int w = (height*bmpWidth)/bmpHeight;
63
        sinkBmp.move((width-w)/2 ,0, 0);
64
        sinkBmp.scale((float)height/bmpHeight);
65
        }
66
      else
67
        {
68
        int h = (width*bmpHeight)/bmpWidth;
69
        sinkBmp.move(0 ,(height-h)/2, 0);
70
        sinkBmp.scale((float)width/bmpWidth);
71
        }
72
      
73
      Distorted.onSurfaceChanged(width, height); 
74
      }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
    
78
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
79
      {
80
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
81
      Bitmap bitmap;
82
        
83
      try 
84
        {
85
        bitmap = BitmapFactory.decodeStream(is);
86
        } 
87
      finally 
88
        {
89
        try 
90
          {
91
          is.close();
92
          } 
93
        catch(IOException e) { }
94
        }  
95
      
96
      bmpHeight = bitmap.getHeight();
97
      bmpWidth  = bitmap.getWidth();
98
      
99
      sinkBmp = new DistortedBitmap(bitmap, 30);
100
      sinkBmp.sink( 10.0f, Region, pLeft, 2000, 0.0f);
101
      sinkBmp.sink(10.0f, Region, pRight,2000, 0.0f);
102
      
103
      try
104
        {
105
        Distorted.onSurfaceCreated(mView.getContext());
106
        }
107
      catch(Exception ex)
108
        {
109
        android.util.Log.e("Sink", ex.getMessage() );
110
        }
111
      }
112
}
(2-2/3)