Project

General

Profile

« Previous | Next » 

Revision fa9b6494

Added by Leszek Koltunski almost 7 years ago

Convert the first few Apps to the new Effect API.

View differences:

src/main/java/org/distorted/examples/blur/BlurRenderer.java
24 24
import android.opengl.GLSurfaceView;
25 25

  
26 26
import org.distorted.examples.R;
27
import org.distorted.library.effect.EffectName;
28
import org.distorted.library.effect.MatrixEffectMove;
29
import org.distorted.library.effect.MatrixEffectScale;
30
import org.distorted.library.effect.PostprocessEffectBlur;
27 31
import org.distorted.library.main.Distorted;
28 32
import org.distorted.library.main.DistortedEffects;
29 33
import org.distorted.library.main.DistortedEffectsPostprocess;
30 34
import org.distorted.library.main.DistortedNode;
31 35
import org.distorted.library.main.DistortedScreen;
32 36
import org.distorted.library.main.DistortedTexture;
33
import org.distorted.library.EffectNames;
34
import org.distorted.library.EffectTypes;
35 37
import org.distorted.library.main.MeshFlat;
36 38
import org.distorted.library.type.Dynamic1D;
37 39
import org.distorted.library.type.Static1D;
......
54 56
    private DistortedScreen mScreen;
55 57
    private MeshFlat mMesh;
56 58
    private Static1D mRadiusSta;
57
    private int bmpHeight, bmpWidth;
59
    private int mObjHeight, mObjWidth;
60
    private Static3D mMove, mScale;
58 61

  
59 62
///////////////////////////////////////////////////////////////////////////////////////////////////
60 63

  
......
70 73
      Dynamic1D radiusDyn = new Dynamic1D();
71 74
      radiusDyn.add(mRadiusSta);
72 75

  
73
      mPostEffects.blur(radiusDyn);
76
      mMove = new Static3D(0,0,0);
77
      mScale= new Static3D(1,1,1);
78

  
79
      mPostEffects.apply( new PostprocessEffectBlur(radiusDyn) );
80
      mEffects.apply(new MatrixEffectMove(mMove));
81
      mEffects.apply(new MatrixEffectScale(mScale));
74 82
      }
75 83

  
76 84
///////////////////////////////////////////////////////////////////////////////////////////////////
......
91 99

  
92 100
///////////////////////////////////////////////////////////////////////////////////////////////////
93 101
    
94
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
95
      { 
96
      mEffects.abortEffects(EffectTypes.MATRIX);
97
      
98
      if( (float)bmpHeight/bmpWidth > (float)height/width )
99
        {
100
        int w = (height*bmpWidth)/bmpHeight;
101
        float factor = (float)height/bmpHeight;
102

  
103
        mEffects.move( new Static3D((width-w)/2,0,0) );
104
        mEffects.scale(factor);
105
        }
106
      else
107
        {
108
        int h = (width*bmpHeight)/bmpWidth;
109
        float factor = (float)width/bmpWidth;
110

  
111
        mEffects.move( new Static3D(0,(height-h)/2,0) );
112
        mEffects.scale(factor);
113
        }
114
      
115
      mScreen.resize(width, height);
116
      }
102
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
103
     {
104
     if( (float)mObjHeight/mObjWidth > (float)height/width )
105
       {
106
       int w = (height*mObjWidth)/mObjHeight;
107
       float factor = (float)height/mObjHeight;
108
       mMove.set((width-w)/2,0,0);
109
       mScale.set(factor,factor,factor);
110
       }
111
     else
112
       {
113
       int h = (width*mObjHeight)/mObjWidth;
114
       float factor = (float)width/mObjWidth;
115
       mMove.set(0,(height-h)/2,0);
116
       mScale.set(factor,factor,factor);
117
       }
118

  
119
     mScreen.resize(width,height);
120
     }
117 121

  
118 122
///////////////////////////////////////////////////////////////////////////////////////////////////
119 123
    
120
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
121
      {
122
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
123
      Bitmap bitmap;
124
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
125
     {
126
     InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
127
     Bitmap bitmap;
124 128
        
125
      try 
126
        {
127
        bitmap = BitmapFactory.decodeStream(is);
128
        } 
129
      finally 
130
        {
131
        try 
132
          {
133
          is.close();
134
          } 
135
        catch(IOException e) { }
136
        }  
129
     try
130
       {
131
       bitmap = BitmapFactory.decodeStream(is);
132
       }
133
     finally
134
       {
135
       try
136
         {
137
         is.close();
138
         }
139
       catch(IOException e) { }
140
       }
137 141
      
138
      bmpHeight = bitmap.getHeight();
139
      bmpWidth  = bitmap.getWidth();
140

  
141
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
142
      mTexture.setTexture(bitmap);
143

  
144
      mScreen.detachAll();
145
      DistortedNode node = new DistortedNode(mTexture,mEffects,mMesh);
146
      node.setPostprocessEffects(mPostEffects);
147
      mScreen.attach(node);
148

  
149
      DistortedEffects.enableEffect(EffectNames.BLUR);
150

  
151
      try
152
        {
153
        Distorted.onCreate(mView.getContext());
154
        }
155
      catch(Exception ex)
156
        {
157
        android.util.Log.e("Blur", ex.getMessage() );
158
        }
159
      }
142
     mObjHeight = bitmap.getHeight();
143
     mObjWidth  = bitmap.getWidth();
144

  
145
     if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
146
     mTexture.setTexture(bitmap);
147

  
148
     mScreen.detachAll();
149
     DistortedNode node = new DistortedNode(mTexture,mEffects,mMesh);
150
     node.setPostprocessEffects(mPostEffects);
151
     mScreen.attach(node);
152

  
153
     DistortedEffects.enableEffect(EffectName.BLUR);
154

  
155
     try
156
       {
157
       Distorted.onCreate(mView.getContext());
158
       }
159
     catch(Exception ex)
160
       {
161
       android.util.Log.e("Blur", ex.getMessage() );
162
       }
163
     }
160 164
}

Also available in: Unified diff