Project

General

Profile

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

examples / src / main / java / org / distorted / examples / movingeffects / MovingEffectsRenderer.java @ 7451c98a

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 5068fa06 Leszek Koltunski
package org.distorted.examples.movingeffects;
21 427ab7bf Leszek Koltunski
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 f6d884d5 Leszek Koltunski
import org.distorted.library.DistortedTexture;
33
import org.distorted.library.DistortedEffectQueues;
34 10b7e588 Leszek Koltunski
import org.distorted.library.GridFlat;
35 5068fa06 Leszek Koltunski
import org.distorted.library.Distorted;
36 427ab7bf Leszek Koltunski
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39 97dadfe5 Leszek Koltunski
class MovingEffectsRenderer implements GLSurfaceView.Renderer
40 427ab7bf Leszek Koltunski
   {  
41 4562f295 Leszek Koltunski
   private MovingEffectsSurfaceView mView;
42 427ab7bf Leszek Koltunski
   private Canvas mCanvas;
43
   private Bitmap mBitmap;
44
   private Paint mPaint;
45 97dadfe5 Leszek Koltunski
   private int texW, texH;
46
47 10b7e588 Leszek Koltunski
   private GridFlat mGrid;
48 f6d884d5 Leszek Koltunski
   private DistortedEffectQueues mQueues;
49
   private DistortedTexture mTexture;
50 97dadfe5 Leszek Koltunski
51 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
52
53 4562f295 Leszek Koltunski
   MovingEffectsRenderer(MovingEffectsSurfaceView v)
54 427ab7bf Leszek Koltunski
     {    
55
     mPaint = new Paint();
56
     mPaint.setAntiAlias(true);
57
     mPaint.setFakeBoldText(true);
58
     mPaint.setStyle(Style.FILL);
59
      
60
     mView = v;
61 f6d884d5 Leszek Koltunski
62
     mQueues = new DistortedEffectQueues();
63 427ab7bf Leszek Koltunski
     }
64
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
67
   private void drawBackground()
68
     {
69 97dadfe5 Leszek Koltunski
     int NW, NH;
70
71
     if( texH<texW )
72
       {
73
       NH = 10;
74
       NW = NH*texW/texH;
75
       }
76
     else
77
       {
78
       NW = 10;
79
       NH = NW*texH/texW;
80
       }
81
82 427ab7bf Leszek Koltunski
     mPaint.setColor(0xff008800);
83 97dadfe5 Leszek Koltunski
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
84 427ab7bf Leszek Koltunski
     mPaint.setColor(0xffffffff);
85
         
86 97dadfe5 Leszek Koltunski
     for(int i=0; i<=NH ; i++ ) mCanvas.drawRect( 0, texH*i/NH -2,  texW,  texH*i/NH + 2, mPaint);
87
     for(int i=0; i<=NW ; i++ ) mCanvas.drawRect( texW*i/NW - 2, 0, texW*i/NW + 2,  texH, mPaint);
88 427ab7bf Leszek Koltunski
     }
89
   
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91 f6d884d5 Leszek Koltunski
92
   DistortedEffectQueues getQueues()
93
     {
94
     return mQueues;
95
     }
96
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99 427ab7bf Leszek Koltunski
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
100 97dadfe5 Leszek Koltunski
     {
101 427ab7bf Leszek Koltunski
     try
102 97dadfe5 Leszek Koltunski
       {
103
       Distorted.onSurfaceCreated(mView.getContext());
104
       }
105
     catch(Exception ex)
106
       {
107
       android.util.Log.e("Renderer", ex.getMessage() );
108
       }
109 427ab7bf Leszek Koltunski
     }
110
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112
113
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
114
     {
115 97dadfe5 Leszek Koltunski
     texW = width;
116
     texH = height;
117
118 f6d884d5 Leszek Koltunski
     mGrid    = new GridFlat(80,80*texH/texW);
119 7451c98a Leszek Koltunski
     mTexture = new DistortedTexture(texW,texH);
120 f6d884d5 Leszek Koltunski
     mBitmap  = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
121
     mCanvas  = new Canvas(mBitmap);
122 97dadfe5 Leszek Koltunski
123
     Distorted.onSurfaceChanged(texW, texH);
124 4562f295 Leszek Koltunski
     mView.onSurfaceChanged(texW,texH);
125 427ab7bf Leszek Koltunski
     }
126
   
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
   
129
   public void onDrawFrame(GL10 glUnused)
130
     {   
131
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);               
132
       
133
     long time = System.currentTimeMillis();
134
      
135 4562f295 Leszek Koltunski
     if (mView.getCurrentEffect() == MovingEffectsSurfaceView.EFFECT_POINTS )
136 427ab7bf Leszek Koltunski
       {
137
       drawBackground();   
138 4562f295 Leszek Koltunski
       mView.drawCurve(mCanvas,time);
139 f6d884d5 Leszek Koltunski
       mTexture.setTexture(mBitmap);
140 427ab7bf Leszek Koltunski
       }
141
      
142 f6d884d5 Leszek Koltunski
     mQueues.draw(time,mTexture,mGrid);
143 427ab7bf Leszek Koltunski
     }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
}