Project

General

Profile

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

examples / src / main / java / org / distorted / examples / movingeffects / MovingEffectsRenderer.java @ bc0a685b

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.examples.movingeffects;
21

    
22
import javax.microedition.khronos.egl.EGLConfig;
23
import javax.microedition.khronos.opengles.GL10;
24

    
25
import android.graphics.Bitmap;
26
import android.graphics.Canvas;
27
import android.graphics.Paint;
28
import android.graphics.Paint.Style;
29
import android.opengl.GLES20;
30
import android.opengl.GLSurfaceView;
31

    
32
import org.distorted.library.DistortedBitmap;
33
import org.distorted.library.Distorted;
34
import org.distorted.library.EffectTypes;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class MovingEffectsRenderer implements GLSurfaceView.Renderer 
39
   {  
40
   public static final int NUMLINES = 10;
41
   public static final int BWID = 300;
42
   public static final int BHEI = 400;
43
   
44
   private GLSurfaceView mView;
45
   public static DistortedBitmap mBackground;
46
   private Canvas mCanvas;
47
   private Bitmap mBitmap;
48
   private Paint mPaint;
49
   private int texWidth, texHeight;
50
    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
   public MovingEffectsRenderer(GLSurfaceView v)
54
     {    
55
     mPaint = new Paint();
56
     mPaint.setAntiAlias(true);
57
     mPaint.setFakeBoldText(true);
58
     mPaint.setStyle(Style.FILL);
59
      
60
     mView = v;
61
      
62
     texWidth = BWID;
63
     texHeight= BHEI;
64
     }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
   private void drawBackground()
69
     {
70
     mPaint.setColor(0xff008800);
71
     mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
72
     mPaint.setColor(0xffffffff);
73
         
74
     for(int i=0; i<=NUMLINES ; i++ )
75
       {
76
       mCanvas.drawRect(texWidth*i/NUMLINES - 2,                       0,  texWidth*i/NUMLINES + 2,  texHeight               , mPaint);
77
       mCanvas.drawRect(                      0, texHeight*i/NUMLINES -2,  texWidth               ,  texHeight*i/NUMLINES + 2, mPaint);  
78
       } 
79
     }
80
   
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
   
83
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
84
     {         
85
     mBackground = new DistortedBitmap(texWidth,texHeight, 80);   
86
     mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
87
     mCanvas = new Canvas(mBitmap); 
88
      
89
     try
90
        {
91
        Distorted.onSurfaceCreated(mView.getContext());
92
        }
93
      catch(Exception ex)
94
        {
95
        android.util.Log.e("Renderer", ex.getMessage() );
96
        }
97
     }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
102
     {
103
     mBackground.abortEffects(EffectTypes.MATRIX);
104
     mBackground.scale((float)width/texWidth,(float)height/texHeight,1);
105
   
106
     Distorted.onSurfaceChanged(width, height);
107
     MovingEffectsSurfaceView.setScreenSize(width, height);    
108
     }
109
   
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111
   
112
   public void onDrawFrame(GL10 glUnused)
113
     {   
114
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);               
115
       
116
     long time = System.currentTimeMillis();
117
      
118
     if (MovingEffectsSurfaceView.getCurrentEffect() == MovingEffectsSurfaceView.EFFECT_POINTS )
119
       {
120
       drawBackground();   
121
       MovingEffectsSurfaceView.drawCurve(mCanvas,time);
122
       mBackground.setBitmap(mBitmap);  
123
       }
124
      
125
     mBackground.draw(time);
126
     }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
}
(2-2/3)