Project

General

Profile

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

examples / src / main / java / org / distorted / examples / interpolator / InterpolatorRenderer.java @ bc0a685b

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.interpolator;
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
import org.distorted.library.EffectTypes;
35

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

    
38
public class InterpolatorRenderer implements GLSurfaceView.Renderer 
39
   {  
40
   public static final int BWID = 300;
41
   public static final int BHEI = 400;
42
   
43
   private GLSurfaceView mView;
44
   private DistortedBitmap mBackground;
45
   private Canvas mCanvas;
46
   private Bitmap mBitmap;
47
   private Paint mPaint;
48
   private int texWidth, texHeight;
49
    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
   public InterpolatorRenderer(GLSurfaceView v)
53
     {    
54
     mPaint = new Paint();
55
     mPaint.setAntiAlias(true);
56
     mPaint.setFakeBoldText(true);
57
     mPaint.setColor(0xff447da7);
58
     mPaint.setStyle(Style.FILL);
59
      
60
     mView = v;
61
      
62
     texWidth = BWID;
63
     texHeight= BHEI;
64
     }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
   
68
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
69
     {   
70
     mBackground = new DistortedBitmap(texWidth,texHeight, 2);    
71
     mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
72
     mCanvas = new Canvas(mBitmap);
73
     
74
     try
75
        {
76
        Distorted.onSurfaceCreated(mView.getContext());
77
        }
78
      catch(Exception ex)
79
        {
80
        android.util.Log.e("Renderer", ex.getMessage() );
81
        }
82
     }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
87
     {
88
     mBackground.abortEffects(EffectTypes.MATRIX);
89
     mBackground.scale((float)width/texWidth,(float)height/texHeight,1);
90
     Distorted.onSurfaceChanged(width, height);
91
     InterpolatorSurfaceView.setScreenSize(width,height);
92
     }
93
   
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95
   
96
   public void onDrawFrame(GL10 glUnused)
97
     {   
98
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);               
99
       
100
     long time = System.currentTimeMillis();
101
      
102
     mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
103
     InterpolatorSurfaceView.drawCurve(mCanvas,time);
104
     mBackground.setBitmap(mBitmap);
105
     mBackground.draw(time);
106
     }
107

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