Project

General

Profile

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

examples / src / main / java / org / distortedandroid / examples / interpolator / InterpolatorRenderer.java @ 427ab7bf

1
package org.distortedandroid.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.distortedandroid.library.DistortedBitmap;
14
import org.distortedandroid.library.Distorted;
15

    
16
///////////////////////////////////////////////////////////////////////////////////////////////////
17

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

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

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

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