Project

General

Profile

« Previous | Next » 

Revision bc0a685b

Added by Leszek Koltunski almost 8 years ago

Add License

View differences:

src/main/java/org/distorted/examples/sink/SinkRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
1 19

  
2 20
package org.distorted.examples.sink;
3 21

  
......
23 41
///////////////////////////////////////////////////////////////////////////////////////////////////
24 42

  
25 43
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;
44
  {
45
  private GLSurfaceView mView;
46
  private DistortedBitmap sinkBmp;
47
  private Float2D pLeft, pRight;
48
  private Float4D Region;
49
  private int bmpHeight, bmpWidth;
32 50
    
33 51
///////////////////////////////////////////////////////////////////////////////////////////////////
34 52

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

  
44 62
///////////////////////////////////////////////////////////////////////////////////////////////////
45 63
   
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);
64
  public void onDrawFrame(GL10 glUnused) 
65
    {
66
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
67
    GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
50 68
      
51
      sinkBmp.draw(System.currentTimeMillis());
52
      }
69
    sinkBmp.draw(System.currentTimeMillis());
70
    }
53 71

  
54 72
///////////////////////////////////////////////////////////////////////////////////////////////////
55 73
    
56
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
57
      { 
58
      sinkBmp.abortEffects(EffectTypes.MATRIX);
74
  public void onSurfaceChanged(GL10 glUnused, int width, int height) 
75
    { 
76
    sinkBmp.abortEffects(EffectTypes.MATRIX);
59 77
         
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); 
78
    if( bmpHeight/bmpWidth > height/width )
79
      {
80
      int w = (height*bmpWidth)/bmpHeight;
81
      sinkBmp.move((width-w)/2 ,0, 0);
82
      sinkBmp.scale((float)height/bmpHeight);
83
      }
84
    else
85
      {
86
      int h = (width*bmpHeight)/bmpWidth;
87
      sinkBmp.move(0 ,(height-h)/2, 0);
88
      sinkBmp.scale((float)width/bmpWidth);
74 89
      }
90
      
91
    Distorted.onSurfaceChanged(width, height); 
92
    }
75 93

  
76 94
///////////////////////////////////////////////////////////////////////////////////////////////////
77 95
    
78
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
79
      {
80
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
81
      Bitmap bitmap;
96
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
97
    {
98
    InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
99
    Bitmap bitmap;
82 100
        
101
    try 
102
      {
103
      bitmap = BitmapFactory.decodeStream(is);
104
      } 
105
    finally 
106
      {
83 107
      try 
84 108
        {
85
        bitmap = BitmapFactory.decodeStream(is);
109
        is.close();
86 110
        } 
87
      finally 
88
        {
89
        try 
90
          {
91
          is.close();
92
          } 
93
        catch(IOException e) { }
94
        }  
111
      catch(IOException e) { }
112
      }  
95 113
      
96
      bmpHeight = bitmap.getHeight();
97
      bmpWidth  = bitmap.getWidth();
114
    bmpHeight = bitmap.getHeight();
115
    bmpWidth  = bitmap.getWidth();
98 116
      
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);
117
    sinkBmp = new DistortedBitmap(bitmap, 30);
118
    sinkBmp.sink( 10.0f, Region, pLeft, 2000, 0.0f);
119
    sinkBmp.sink(10.0f, Region, pRight,2000, 0.0f);
102 120
      
103
      try
104
        {
105
        Distorted.onSurfaceCreated(mView.getContext());
106
        }
107
      catch(Exception ex)
108
        {
109
        android.util.Log.e("Sink", ex.getMessage() );
110
        }
121
    try
122
      {
123
      Distorted.onSurfaceCreated(mView.getContext());
124
      }
125
    catch(Exception ex)
126
      {
127
      android.util.Log.e("Sink", ex.getMessage() );
111 128
      }
112
}
129
    }
130
  }

Also available in: Unified diff