Project

General

Profile

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

examples / src / main / java / org / distorted / examples / dynamic / DynamicRenderer.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.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.DistortedObject;
34
import org.distorted.library.Distorted;
35

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

    
38
class DynamicRenderer implements GLSurfaceView.Renderer
39
   {  
40
   private DynamicSurfaceView mView;
41
   private DistortedObject mBackground;
42
   private GridFlat mGrid;
43
   private Canvas mCanvas;
44
   private Bitmap mBitmap;
45
   private Paint mPaint;
46

    
47
   static int texW, texH;
48
    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
   DynamicRenderer(DynamicSurfaceView v)
52
     {    
53
     mPaint = new Paint();
54
     mPaint.setAntiAlias(true);
55
     mPaint.setFakeBoldText(true);
56
     mPaint.setColor(0xff447da7);
57
     mPaint.setStyle(Style.FILL);
58
      
59
     mView = v;
60
     }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
   
64
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
65
     {   
66
     try
67
        {
68
        Distorted.onSurfaceCreated(mView.getContext());
69
        }
70
      catch(Exception ex)
71
        {
72
        android.util.Log.e("Renderer", ex.getMessage() );
73
        }
74
     }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
79
     {
80
     texW = width;
81
     texH = height;
82

    
83
     mGrid       = new GridFlat(1,1);
84
     mBackground = new DistortedObject(texW,texH,1);
85
     mBitmap     = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
86
     mCanvas     = new Canvas(mBitmap);
87

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

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
  }
(2-2/3)