Project

General

Profile

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

examples / src / main / java / org / distorted / examples / movingeffects / MovingEffectsRenderer.java @ 10b7e588

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.DistortedObject;
33
import org.distorted.library.GridFlat;
34
import org.distorted.library.Distorted;
35

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

    
38
class MovingEffectsRenderer implements GLSurfaceView.Renderer
39
   {  
40
   private MovingEffectsSurfaceView mView;
41
   private Canvas mCanvas;
42
   private Bitmap mBitmap;
43
   private Paint mPaint;
44
   private int texW, texH;
45

    
46
   private GridFlat mGrid;
47

    
48
   static DistortedObject mBackground;
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
   MovingEffectsRenderer(MovingEffectsSurfaceView v)
53
     {    
54
     mPaint = new Paint();
55
     mPaint.setAntiAlias(true);
56
     mPaint.setFakeBoldText(true);
57
     mPaint.setStyle(Style.FILL);
58
      
59
     mView = v;
60
     }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
   private void drawBackground()
65
     {
66
     int NW, NH;
67

    
68
     if( texH<texW )
69
       {
70
       NH = 10;
71
       NW = NH*texW/texH;
72
       }
73
     else
74
       {
75
       NW = 10;
76
       NH = NW*texH/texW;
77
       }
78

    
79
     mPaint.setColor(0xff008800);
80
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
81
     mPaint.setColor(0xffffffff);
82
         
83
     for(int i=0; i<=NH ; i++ ) mCanvas.drawRect( 0, texH*i/NH -2,  texW,  texH*i/NH + 2, mPaint);
84
     for(int i=0; i<=NW ; i++ ) mCanvas.drawRect( texW*i/NW - 2, 0, texW*i/NW + 2,  texH, mPaint);
85
     }
86
   
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
   
89
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
90
     {
91
     try
92
       {
93
       Distorted.onSurfaceCreated(mView.getContext());
94
       }
95
     catch(Exception ex)
96
       {
97
       android.util.Log.e("Renderer", ex.getMessage() );
98
       }
99
     }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
104
     {
105
     texW = width;
106
     texH = height;
107

    
108
     mGrid = new GridFlat(80,80*height/width);
109
     mBackground = new DistortedObject(texW,texH,1);
110
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
111
     mCanvas = new Canvas(mBitmap);
112

    
113
     Distorted.onSurfaceChanged(texW, texH);
114
     mView.onSurfaceChanged(texW,texH);
115
     }
116
   
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118
   
119
   public void onDrawFrame(GL10 glUnused)
120
     {   
121
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);               
122
       
123
     long time = System.currentTimeMillis();
124
      
125
     if (mView.getCurrentEffect() == MovingEffectsSurfaceView.EFFECT_POINTS )
126
       {
127
       drawBackground();   
128
       mView.drawCurve(mCanvas,time);
129
       mBackground.setTexture(mBitmap);
130
       }
131
      
132
     mBackground.draw(time,mGrid);
133
     }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
}
(2-2/3)