Project

General

Profile

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

examples / src / main / java / org / distorted / examples / movingeffects / MovingEffectsRenderer.java @ 9c5b5cb6

1
package org.distorted.examples.movingeffects;
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 MovingEffectsRenderer implements GLSurfaceView.Renderer 
20
   {  
21
   public static final int NUMLINES = 10;
22
   public static final int BWID = 300;
23
   public static final int BHEI = 400;
24
   
25
   private GLSurfaceView mView;
26
   public static DistortedBitmap mBackground;
27
   private Canvas mCanvas;
28
   private Bitmap mBitmap;
29
   private Paint mPaint;
30
   private int texWidth, texHeight;
31
    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

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

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
   private void drawBackground()
50
     {
51
     mPaint.setColor(0xff008800);
52
     mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
53
     mPaint.setColor(0xffffffff);
54
         
55
     for(int i=0; i<=NUMLINES ; i++ )
56
       {
57
       mCanvas.drawRect(texWidth*i/NUMLINES - 2,                       0,  texWidth*i/NUMLINES + 2,  texHeight               , mPaint);
58
       mCanvas.drawRect(                      0, texHeight*i/NUMLINES -2,  texWidth               ,  texHeight*i/NUMLINES + 2, mPaint);  
59
       } 
60
     }
61
   
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
   
64
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
65
     {         
66
     mBackground = new DistortedBitmap(texWidth,texHeight, 80);   
67
     mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
68
     mCanvas = new Canvas(mBitmap); 
69
      
70
     try
71
        {
72
        Distorted.onSurfaceCreated(mView.getContext());
73
        }
74
      catch(Exception ex)
75
        {
76
        android.util.Log.e("Renderer", ex.getMessage() );
77
        }
78
     }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
83
     {
84
     mBackground.abortEffects(EffectTypes.MATRIX);
85
     mBackground.scale((float)width/texWidth,(float)height/texHeight,1);
86
   
87
     Distorted.onSurfaceChanged(width, height);
88
     MovingEffectsSurfaceView.setScreenSize(width, height);    
89
     }
90
   
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
   
93
   public void onDrawFrame(GL10 glUnused)
94
     {   
95
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);               
96
       
97
     long time = System.currentTimeMillis();
98
      
99
     if (MovingEffectsSurfaceView.getCurrentEffect() == MovingEffectsSurfaceView.EFFECT_POINTS )
100
       {
101
       drawBackground();   
102
       MovingEffectsSurfaceView.drawCurve(mCanvas,time);
103
       mBackground.setBitmap(mBitmap);  
104
       }
105
      
106
     mBackground.draw(time);
107
     }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
}
(2-2/3)