Project

General

Profile

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

examples / src / main / java / org / distorted / examples / dynamic / DynamicRenderer.java @ 3c8b1903

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.dynamic;
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.GridFlat;
33
import org.distorted.library.DistortedEffectQueues;
34
import org.distorted.library.DistortedTexture;
35
import org.distorted.library.Distorted;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
class DynamicRenderer implements GLSurfaceView.Renderer
40
   {  
41
   private DynamicSurfaceView mView;
42
   private DistortedTexture mTexture;
43
   private DistortedEffectQueues mQueues;
44
   private GridFlat mGrid;
45
   private Canvas mCanvas;
46
   private Bitmap mBitmap;
47
   private Paint mPaint;
48

    
49
   static int texW, texH;
50
    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
   DynamicRenderer(DynamicSurfaceView v)
54
     {    
55
     mPaint = new Paint();
56
     mPaint.setAntiAlias(true);
57
     mPaint.setFakeBoldText(true);
58
     mPaint.setColor(0xff447da7);
59
     mPaint.setStyle(Style.FILL);
60
      
61
     mView   = v;
62
     mGrid   = new GridFlat(1,1);
63
     mQueues = new DistortedEffectQueues();
64
     }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
   
68
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
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
     texW = width;
85
     texH = height;
86

    
87
     mTexture= new DistortedTexture(texW,texH);
88
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
89
     mCanvas = new Canvas(mBitmap);
90

    
91
     Distorted.onSurfaceChanged(texW,texH);
92
     mView.onSurfaceChanged(texW,texH);
93
     }
94
   
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
   
97
   public void onDrawFrame(GL10 glUnused)
98
     {   
99
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);               
100
       
101
     long time = System.currentTimeMillis();
102
      
103
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
104
     mView.drawCurve(mCanvas,time);
105
     mTexture.setTexture(mBitmap);
106
     mQueues.draw(time,mTexture,mGrid);
107
     }
108

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