Project

General

Profile

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

examples / src / main / java / org / distorted / examples / macroblock / MacroblockRenderer.java @ 7589635e

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 5068fa06 Leszek Koltunski
package org.distorted.examples.macroblock;
21 427ab7bf Leszek Koltunski
22
import java.io.IOException;
23
import java.io.InputStream;
24
25
import javax.microedition.khronos.egl.EGLConfig;
26
import javax.microedition.khronos.opengles.GL10;
27
28 5068fa06 Leszek Koltunski
import org.distorted.examples.R;
29
import org.distorted.library.Distorted;
30
import org.distorted.library.DistortedBitmap;
31 95593730 Leszek Koltunski
import org.distorted.library.EffectTypes;
32 7589635e Leszek Koltunski
import org.distorted.library.type.Dynamic1D;
33
import org.distorted.library.type.Dynamic3D;
34
import org.distorted.library.type.Static1D;
35
import org.distorted.library.type.Static2D;
36
import org.distorted.library.type.Static3D;
37
import org.distorted.library.type.Static4D;
38 427ab7bf Leszek Koltunski
39
import android.graphics.Bitmap;
40
import android.graphics.BitmapFactory;
41
import android.opengl.GLES20;
42
import android.opengl.GLSurfaceView;
43
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46
class MacroblockRenderer implements GLSurfaceView.Renderer 
47
{
48
    private GLSurfaceView mView;
49
    private DistortedBitmap macroblock;
50 7589635e Leszek Koltunski
    private Static4D Region;
51 427ab7bf Leszek Koltunski
    private int bmpHeight, bmpWidth;
52 7589635e Leszek Koltunski
    private Static2D traP, macP;
53 427ab7bf Leszek Koltunski
    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56
    public MacroblockRenderer(GLSurfaceView v) 
57
      {   
58
      mView = v;
59
      
60 7589635e Leszek Koltunski
      Region = new Static4D(0,0,100,100);
61
      macP   = new Static2D(530,200);
62
      traP   = new Static2D(230,200);
63 427ab7bf Leszek Koltunski
      }
64
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
   
67
    public void onDrawFrame(GL10 glUnused) 
68
      {
69
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
70
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
71
   
72
      macroblock.draw(System.currentTimeMillis());
73
      }
74
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
    
77
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
78
      {  
79
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.cat_and_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
      macroblock = new DistortedBitmap(bitmap, 30);    
99
      macroblock.macroblock(  30, Region, macP, 3000, 0.0f);
100
      macroblock.alpha     (0.0f, Region, traP, 3000, 0.0f);
101
      
102
      try
103
        {
104 ed1c0b33 Leszek Koltunski
        Distorted.onSurfaceCreated(mView.getContext());
105 427ab7bf Leszek Koltunski
        }
106
      catch(Exception ex)
107
        {
108
        android.util.Log.e("Renderer", ex.getMessage() );
109
        }
110
      }
111
    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
    
114
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
115
      {
116
      int duration = 10000;   
117
      
118 7589635e Leszek Koltunski
      Dynamic3D diMove = new Dynamic3D();
119 427ab7bf Leszek Koltunski
      diMove.setCount(0.0f);
120
      diMove.setDuration(duration);
121 7589635e Leszek Koltunski
      diMove.add(new Static3D(width-bmpWidth,height-bmpHeight,0));
122
      diMove.add(new Static3D(0,0,0));
123 427ab7bf Leszek Koltunski
      
124 7589635e Leszek Koltunski
      Dynamic3D diScale = new Dynamic3D();
125 427ab7bf Leszek Koltunski
      diScale.setCount(0.0f);
126
      diScale.setDuration(duration);
127 7589635e Leszek Koltunski
      diScale.add(new Static3D(1,1,1));
128
      diScale.add(new Static3D(0.33f,0.33f,1));
129 427ab7bf Leszek Koltunski
      
130 7589635e Leszek Koltunski
      Dynamic1D diRotate = new Dynamic1D();
131 427ab7bf Leszek Koltunski
      diRotate.setCount(0.0f);
132
      diRotate.setDuration(duration);
133 7589635e Leszek Koltunski
      diRotate.add(new Static1D(  0));
134
      diRotate.add(new Static1D(360));
135 427ab7bf Leszek Koltunski
      
136 a8c3ada7 Leszek Koltunski
      macroblock.abortEffects(EffectTypes.MATRIX);
137 427ab7bf Leszek Koltunski
138
      macroblock.move(diMove);
139
      macroblock.scale(diScale);
140 7589635e Leszek Koltunski
      macroblock.rotate( new Static3D(bmpWidth/2,bmpHeight/2,0), diRotate, new Static3D(0,0,1) );
141
142 427ab7bf Leszek Koltunski
      Distorted.onSurfaceChanged(width, height); 
143
      }
144
}