Project

General

Profile

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

examples / src / main / java / org / distorted / examples / save / SaveRenderer.java @ a2cb31e9

1

    
2
package org.distorted.examples.save;
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.Float1D;
16
import org.distorted.library.Float2D;
17
import org.distorted.library.Float4D;
18
import org.distorted.library.Interpolator1D;
19

    
20
import android.graphics.Bitmap;
21
import android.graphics.BitmapFactory;
22
import android.opengl.GLES20;
23
import android.opengl.GLSurfaceView;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
class SaveRenderer implements GLSurfaceView.Renderer 
28
{
29
    private GLSurfaceView mView;
30
    private DistortedBitmap mGirl;
31
    private Float2D pLeft, pRight;
32
    private Float4D sinkRegion;
33
    private static Interpolator1D diSink;
34
    private static Float1D s0;
35
    
36
    private int bmpHeight, bmpWidth;
37
    
38
    private static float boobsSink;
39
    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
   public SaveRenderer(GLSurfaceView v) 
43
      {
44
      mView = v;
45
      
46
      boobsSink  = 1.0f;
47
      
48
      pLeft = new Float2D(132, 264);
49
      pRight= new Float2D(247, 264);
50
      
51
      // Make the boobs bigger
52
      sinkRegion = new Float4D(0,0,60,60);
53
      
54
      s0 = new Float1D(boobsSink);
55
      
56
      diSink = new Interpolator1D(); 
57
      diSink.setCount(0.5f);
58
      diSink.setDuration(0);
59
      diSink.add(s0);
60
      }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
   public static void setSize(float s)
65
     {
66
     boobsSink = s;
67
     s0.set(boobsSink);
68
     }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
   
72
   public void onDrawFrame(GL10 glUnused) 
73
      {
74
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
75
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
76
      
77
      mGirl.draw(System.currentTimeMillis());
78
      }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
    
82
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
83
      { 
84
      mGirl.abortEffects(EffectTypes.MATRIX);
85
      
86
      if( bmpHeight/bmpWidth > height/width )
87
        {
88
        int w = (height*bmpWidth)/bmpHeight;
89
        mGirl.move((width-w)/2 ,0, 0);
90
        mGirl.scale((float)height/bmpHeight);
91
        }
92
      else
93
        {
94
        int h = (width*bmpHeight)/bmpWidth;
95
        mGirl.move(0 ,(height-h)/2, 0);
96
        mGirl.scale((float)width/bmpWidth);
97
        }
98
      
99
      Distorted.onSurfaceChanged(width, height); 
100
      }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
    
104
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
105
      {    
106
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
107
      Bitmap bitmap;
108
        
109
      try 
110
        {
111
        bitmap = BitmapFactory.decodeStream(is);
112
        } 
113
      finally 
114
        {
115
        try 
116
          {
117
          is.close();
118
          } 
119
        catch(IOException e) { }
120
        }  
121
      
122
      bmpHeight = bitmap.getHeight();
123
      bmpWidth  = bitmap.getWidth();
124
      
125
      mGirl = new DistortedBitmap(bitmap, 30);
126

    
127
      mGirl.sink( diSink, sinkRegion, pLeft );
128
      mGirl.sink( diSink, sinkRegion, pRight);
129

    
130
      try
131
        {
132
        Distorted.onSurfaceCreated(mView.getContext());
133
        }
134
      catch(Exception ex)
135
        {
136
        android.util.Log.e("Renderer", ex.getMessage() );
137
        }
138
      }
139
}
(2-2/3)