Project

General

Profile

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

examples / src / main / java / org / distorted / examples / interpolator / InterpolatorRenderer.java @ 95593730

1
package org.distorted.examples.interpolator;
2

    
3
import javax.microedition.khronos.egl.EGLConfig;
4
import javax.microedition.khronos.opengles.GL10;
5

    
6
import android.graphics.Bitmap;
7
import android.graphics.Canvas;
8
import android.graphics.Paint;
9
import android.graphics.Paint.Style;
10
import android.opengl.GLES20;
11
import android.opengl.GLSurfaceView;
12

    
13
import org.distorted.library.DistortedBitmap;
14
import org.distorted.library.Distorted;
15
import org.distorted.library.EffectTypes;
16

    
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18

    
19
public class InterpolatorRenderer implements GLSurfaceView.Renderer 
20
   {  
21
   public static final int BWID = 300;
22
   public static final int BHEI = 400;
23
   
24
   private GLSurfaceView mView;
25
   private DistortedBitmap mBackground;
26
   private Canvas mCanvas;
27
   private Bitmap mBitmap;
28
   private Paint mPaint;
29
   private int texWidth, texHeight;
30
    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
   public InterpolatorRenderer(GLSurfaceView v)
34
     {    
35
     mPaint = new Paint();
36
     mPaint.setAntiAlias(true);
37
     mPaint.setFakeBoldText(true);
38
     mPaint.setColor(0xff447da7);
39
     mPaint.setStyle(Style.FILL);
40
      
41
     mView = v;
42
      
43
     texWidth = BWID;
44
     texHeight= BHEI;
45
     }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
   
49
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
50
     {   
51
     mBackground = new DistortedBitmap(texWidth,texHeight, 2);    
52
     mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
53
     mCanvas = new Canvas(mBitmap);
54
     
55
     try
56
        {
57
        Distorted.onSurfaceCreated(mView.getContext());
58
        }
59
      catch(Exception ex)
60
        {
61
        android.util.Log.e("Renderer", ex.getMessage() );
62
        }
63
     }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
68
     {
69
     mBackground.abortAllEffects(EffectTypes.MATRIX.type);
70
     mBackground.scale((float)width/texWidth,(float)height/texHeight,1);
71
     Distorted.onSurfaceChanged(width, height);
72
     InterpolatorSurfaceView.setScreenSize(width,height);
73
     }
74
   
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
   
77
   public void onDrawFrame(GL10 glUnused)
78
     {   
79
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);               
80
       
81
     long time = System.currentTimeMillis();
82
      
83
     mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
84
     InterpolatorSurfaceView.drawCurve(mCanvas,time);
85
     mBackground.setBitmap(mBitmap);
86
     mBackground.draw(time);
87
     }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
  }
(2-2/3)