Project

General

Profile

« Previous | Next » 

Revision 5055b5d4

Added by Leszek Koltunski over 7 years ago

1. (hopefully) finish the 'Save' app (now we can adjust the size of the resulting file)
2. Fix one long-standing bug in almost every single app.

View differences:

src/main/java/org/distorted/examples/differenteffects/DifferentEffectsRenderer.java
77 77

  
78 78
///////////////////////////////////////////////////////////////////////////////////////////////////
79 79
   
80
    public void onDrawFrame(GL10 glUnused) 
81
      {
82
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
80
   public void onDrawFrame(GL10 glUnused)
81
     {
82
     GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
83 83
      
84
      long time = System.currentTimeMillis();
84
     long time = System.currentTimeMillis();
85 85
   
86
      for(int i=NUM-1; i>=0; i--) bmp[i].draw(time);
87
      }
86
     for(int i=NUM-1; i>=0; i--) bmp[i].draw(time);
87
     }
88 88

  
89 89
///////////////////////////////////////////////////////////////////////////////////////////////////
90 90
    
91
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
92
      { 
93
      for(int i=NUM-1; i>=0; i--) 
94
        {   
95
        bmp[i].abortEffects(EffectTypes.MATRIX);
96
        }
91
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
92
     {
93
     for(int i=NUM-1; i>=0; i--)
94
       {
95
       bmp[i].abortEffects(EffectTypes.MATRIX);
96
       }
97 97
      
98
      if( bmpHeight/(NUM*bmpWidth) > height/width )
99
        {
100
        int w = (height*bmpWidth)/bmpHeight;
101
        float factor = (float)height/bmpHeight;
102

  
103
        for(int i=NUM-1; i>=0; i--) 
104
          {
105
          bmp[i].move( new Static3D((width-NUM*w)/2 +i*w , 0, 0) );
106
          bmp[i].scale(factor);
107
          }
108
        }
109
      else
110
        {
111
        int w = width/NUM;  
112
        int h = (width*bmpHeight)/(bmpWidth*NUM);
113
        float factor = (float)width/(bmpWidth*NUM);
114

  
115
        for(int i=NUM-1; i>=0; i--) 
116
          {
117
          bmp[i].move( new Static3D(i*w, (height-h)/2, 0) );
118
          bmp[i].scale(factor);
119
          }
120
        }
98
     if( (float)bmpHeight/(NUM*bmpWidth) > (float)height/width )
99
       {
100
       int w = (height*bmpWidth)/bmpHeight;
101
       float factor = (float)height/bmpHeight;
102

  
103
       for(int i=NUM-1; i>=0; i--)
104
         {
105
         bmp[i].move( new Static3D((width-NUM*w)/2 +i*w , 0, 0) );
106
         bmp[i].scale(factor);
107
         }
108
       }
109
     else
110
       {
111
       int w = width/NUM;
112
       int h = (width*bmpHeight)/(bmpWidth*NUM);
113
       float factor = (float)width/(bmpWidth*NUM);
114

  
115
       for(int i=NUM-1; i>=0; i--)
116
         {
117
         bmp[i].move( new Static3D(i*w, (height-h)/2, 0) );
118
         bmp[i].scale(factor);
119
         }
120
       }
121 121
       
122
      Distorted.onSurfaceChanged(width, height); 
123
      }
122
     Distorted.onSurfaceChanged(width, height);
123
     }
124 124

  
125 125
///////////////////////////////////////////////////////////////////////////////////////////////////
126 126
    
127
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
128
      {
129
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
127
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
128
     {
129
     GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
130 130

  
131
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
132
      Bitmap bitmap;
131
     InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
132
     Bitmap bitmap;
133 133
        
134
      try 
135
        {
136
        bitmap = BitmapFactory.decodeStream(is);
137
        } 
138
      finally 
139
        {
140
        try 
141
          {
142
          is.close();
143
          } 
144
        catch(IOException e) { }
145
        }  
134
     try
135
       {
136
       bitmap = BitmapFactory.decodeStream(is);
137
       }
138
     finally
139
       {
140
       try
141
         {
142
         is.close();
143
         }
144
       catch(IOException e) { }
145
       }
146 146
      
147
      bmpHeight = bitmap.getHeight();
148
      bmpWidth  = bitmap.getWidth();
147
     bmpHeight = bitmap.getHeight();
148
     bmpWidth  = bitmap.getWidth();
149 149
      
150
      bmp = new DistortedBitmap[NUM];
151
      bmp[0] = new DistortedBitmap(bmpWidth, bmpHeight, 30);
150
     bmp = new DistortedBitmap[NUM];
151
     bmp[0] = new DistortedBitmap(bmpWidth, bmpHeight, 30);
152 152
      
153
      for(int i=1; i<NUM; i++) bmp[i] = new DistortedBitmap(bmp[0], Distorted.CLONE_BITMAP);
153
     for(int i=1; i<NUM; i++) bmp[i] = new DistortedBitmap(bmp[0], Distorted.CLONE_BITMAP);
154 154
      
155
      // setting the bitmap once is enough; others are cloned!
156
      bmp[0].setBitmap(bitmap);
155
     // setting the bitmap once is enough; others are cloned!
156
     bmp[0].setBitmap(bitmap);
157 157

  
158
      Dynamic1D sink = new Dynamic1D(2000,0.0f);
159
      sink.add(new Static1D( 1));
160
      sink.add(new Static1D(10));
158
     Dynamic1D sink = new Dynamic1D(2000,0.0f);
159
     sink.add(new Static1D( 1));
160
     sink.add(new Static1D(10));
161 161

  
162
      bmp[0].sink(sink, pLeft, RegionEye);
163
      bmp[0].sink(sink, pRight,RegionEye);
164
      bmp[1].distort(mDI, pNose1);
162
     bmp[0].sink(sink, pLeft, RegionEye);
163
     bmp[0].sink(sink, pRight,RegionEye);
164
     bmp[1].distort(mDI, pNose1);
165 165

  
166
      Dynamic1D chromaDyn = new Dynamic1D(3000,0.0f);
167
      chromaDyn.add(new Static1D(0));
168
      chromaDyn.add(new Static1D(1));
166
     Dynamic1D chromaDyn = new Dynamic1D(3000,0.0f);
167
     chromaDyn.add(new Static1D(0));
168
     chromaDyn.add(new Static1D(1));
169 169

  
170
      bmp[2].chroma(chromaDyn, new Static3D(0,1,0) );
170
     bmp[2].chroma(chromaDyn, new Static3D(0,1,0) );
171 171
      
172
      try
173
        {
174
        Distorted.onSurfaceCreated(mView.getContext());
175
        }
176
      catch(Exception ex)
177
        {
178
        android.util.Log.e("DifferentEffects", ex.getMessage() );
179
        }
180
      }
172
     try
173
       {
174
       Distorted.onSurfaceCreated(mView.getContext());
175
       }
176
     catch(Exception ex)
177
       {
178
       android.util.Log.e("DifferentEffects", ex.getMessage() );
179
       }
180
     }
181 181
}

Also available in: Unified diff