Project

General

Profile

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

examples / src / main / java / org / distorted / examples / dynamic / DynamicRenderer.java @ fe3c72ce

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

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
class DynamicRenderer implements GLSurfaceView.Renderer
38
   {  
39
   private DynamicSurfaceView mView;
40
   private DistortedBitmap mBackground;
41
   private Canvas mCanvas;
42
   private Bitmap mBitmap;
43
   private Paint mPaint;
44

    
45
   static int texW, texH;
46
    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

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

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

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

    
81
     mBackground = new DistortedBitmap(texW,texH, 2);
82
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
83
     mCanvas = new Canvas(mBitmap);
84

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

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
  }
(2-2/3)