Project

General

Profile

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

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

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.DistortedEffects;
33
import org.distorted.library.DistortedFramebuffer;
34
import org.distorted.library.MeshFlat;
35
import org.distorted.library.DistortedTexture;
36
import org.distorted.library.Distorted;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
class DynamicRenderer implements GLSurfaceView.Renderer
41
   {  
42
   private DynamicSurfaceView mView;
43
   private DistortedTexture mTexture;
44
   private DistortedEffects mEffects;
45
   private DistortedFramebuffer mScreen;
46
   private MeshFlat mMesh;
47
   private Canvas mCanvas;
48
   private Bitmap mBitmap;
49
   private Paint mPaint;
50

    
51
   static int texW, texH;
52
    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
   DynamicRenderer(DynamicSurfaceView v)
56
     {    
57
     mPaint = new Paint();
58
     mPaint.setAntiAlias(true);
59
     mPaint.setFakeBoldText(true);
60
     mPaint.setColor(0xff447da7);
61
     mPaint.setStyle(Style.FILL);
62
      
63
     mView   = v;
64
     mMesh = new MeshFlat(1,1);
65
     mEffects = new DistortedEffects();
66
     mScreen = new DistortedFramebuffer(0);
67
     }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
   
71
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
72
     {   
73
     try
74
       {
75
       Distorted.onCreate(mView.getContext());
76
       }
77
     catch(Exception ex)
78
       {
79
       android.util.Log.e("Renderer", ex.getMessage() );
80
       }
81
     }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
86
     {
87
     texW = width;
88
     texH = height;
89

    
90
     mTexture= new DistortedTexture(texW,texH);
91
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
92
     mCanvas = new Canvas(mBitmap);
93

    
94
     mScreen.resize(texW,texH);
95
     mView.onSurfaceChanged(texW,texH);
96
     }
97
   
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
   
100
   public void onDrawFrame(GL10 glUnused)
101
     {   
102
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);               
103
       
104
     long time = System.currentTimeMillis();
105
      
106
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
107
     mView.drawCurve(mCanvas,time);
108
     mTexture.setTexture(mBitmap);
109
     mScreen.renderTo(mTexture, mMesh, mEffects, System.currentTimeMillis() );
110
     }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
  }
(2-2/3)