Project

General

Profile

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

examples / src / main / java / org / distortedandroid / examples / sink / SinkRenderer.java @ 427ab7bf

1

    
2
package org.distortedandroid.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.distortedandroid.examples.R;
11

    
12
import org.distortedandroid.library.Distorted;
13
import org.distortedandroid.library.DistortedBitmap;
14
import org.distortedandroid.library.Float2D;
15
import org.distortedandroid.library.Float4D;
16

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

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

    
24
class SinkRenderer implements GLSurfaceView.Renderer 
25
{
26
   private GLSurfaceView mView;
27
   private DistortedBitmap sinkBmp;
28
   private Float2D pLeft, pRight;
29
   private Float4D Region;
30
   private int bmpHeight, bmpWidth;
31
    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

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

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

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

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