Project

General

Profile

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

examples / src / main / java / org / distorted / examples / fbo / FBORenderer.java @ ed1c0b33

1

    
2
package org.distorted.examples.fbo;
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.DistortedNode;
13
import org.distorted.library.Distorted;
14
import org.distorted.library.DistortedBitmap;
15
import org.distorted.library.Float2D;
16

    
17
import android.graphics.Bitmap;
18
import android.graphics.BitmapFactory;
19
import android.opengl.GLES20;
20
import android.opengl.GLSurfaceView;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

    
24
class FBORenderer implements GLSurfaceView.Renderer 
25
{
26
   private GLSurfaceView mView;
27
   private DistortedBitmap mLisa, mText;
28
   private int lisaHeight, lisaWidth;
29
    
30
   private DistortedNode mRoot;
31
    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
   public FBORenderer(GLSurfaceView v) 
35
      {
36
      mView = v;
37
      }
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
   
41
    public void onDrawFrame(GL10 glUnused) 
42
      {
43
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
44
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
45
      
46
      mRoot.draw(System.currentTimeMillis());
47
      }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
    
51
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
52
      { 
53
      mLisa.abortAllEffects(Distorted.TYPE_MATR);  
54
         
55
      if( lisaHeight/lisaWidth > height/width )
56
        {
57
        int w = (height*lisaWidth)/lisaHeight;
58
        mLisa.move((width-w)/2 ,0, 0);
59
        mLisa.scale((float)height/lisaHeight);
60
        }
61
      else
62
        {
63
        int h = (width*lisaHeight)/lisaWidth;
64
        mLisa.move(0 ,(height-h)/2, 0);
65
        mLisa.scale((float)width/lisaWidth);
66
        }
67
      
68
      Distorted.onSurfaceChanged(width, height); 
69
      }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
    
73
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
74
      {
75
      InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.monalisa);
76
      InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.fbo);
77
      
78
      Bitmap bitmap1, bitmap2;
79
       
80
      try 
81
        {
82
        bitmap1 = BitmapFactory.decodeStream(is1);
83
        bitmap2 = BitmapFactory.decodeStream(is2);
84
        } 
85
      finally 
86
        {
87
        try 
88
          {
89
          is1.close();
90
          is2.close();
91
          } 
92
        catch(IOException e) { }
93
        }  
94
      
95
      lisaHeight = bitmap1.getHeight();
96
      lisaWidth  = bitmap1.getWidth();
97
      
98
      mLisa = new DistortedBitmap(bitmap1, 20);
99
      mText = new DistortedBitmap(bitmap2, 20);
100
      
101
      android.util.Log.e("FBO", "Lisa hashcode= "+bitmap1.hashCode());
102
      
103
      mRoot = new DistortedNode(mLisa);
104
      mRoot.attach(mText);
105
     
106
      int textWidth  = mText.getWidth();
107
      int textHeight = mText.getHeight();
108
      
109
      mText.move(lisaWidth/6 , lisaHeight/3, 0);
110
      mText.scale(lisaWidth/(1.5f*textWidth));
111
      mText.sink(0.5f, new Float2D( textWidth/2, textHeight/2), 5000, 0.0f);
112
      mLisa.macroblock(4, 10000, 0.0f);
113
      
114
      try
115
        {
116
        Distorted.onSurfaceCreated(mView.getContext());
117
        }
118
      catch(Exception ex)
119
        {
120
        android.util.Log.e("MonaLisa", ex.getMessage() );
121
        }
122
      }
123
}
(2-2/3)