Project

General

Profile

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

examples / src / main / java / org / distorted / examples / dynamic / DynamicRenderer.java @ 061449ed

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.GLSurfaceView;
30

    
31
import org.distorted.library.effect.MatrixEffectScale;
32
import org.distorted.library.main.DistortedEffects;
33
import org.distorted.library.main.DistortedScreen;
34
import org.distorted.library.mesh.MeshRectangles;
35
import org.distorted.library.main.DistortedTexture;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.library.type.Static3D;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
class DynamicRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
42
   {  
43
   private DynamicSurfaceView mView;
44
   private DistortedTexture mTexture;
45
   private DistortedEffects mEffects;
46
   private DistortedScreen mScreen;
47
   private MeshRectangles mMesh;
48
   private Canvas mCanvas;
49
   private Bitmap mBitmap;
50
   private Paint mPaint;
51
   private Static3D mScale;
52
   private static int texW, texH;
53
    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

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

    
70
     mScale = new Static3D(1,1,1);
71
     mEffects.apply( new MatrixEffectScale(mScale) );
72
     }
73

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

    
76
   public void onDrawFrame(GL10 glUnused)
77
     {
78
     long time = System.currentTimeMillis();
79

    
80
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
81
     mView.drawCurve(mCanvas,time);
82
     mTexture.setTexture(mBitmap);
83
     mScreen.render( System.currentTimeMillis() );
84
     }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
89
     {
90
     texW = width;
91
     texH = height;
92

    
93
     mScale.set(width,height,1);
94

    
95
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
96
     mCanvas = new Canvas(mBitmap);
97

    
98
     mScreen.detachAll();
99
     mScreen.attach(mTexture,mEffects,mMesh);
100
     mScreen.resize(texW,texH);
101
     mView.onSurfaceChanged(texW,texH);
102
     DynamicSurfaceView.surfaceChanged(texW,texH);
103
     }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
108
     {
109
     DistortedLibrary.onCreate(mView.getContext(),this);
110
     }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
   public void distortedException(Exception ex)
115
     {
116
     android.util.Log.e("Dynamic", ex.getMessage() );
117
     }
118
  }
(2-2/4)