Project

General

Profile

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

examples / src / main / java / org / distorted / examples / dynamic / DynamicRenderer.java @ 77e66c58

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.app.ActivityManager;
26
import android.content.Context;
27
import android.content.pm.ConfigurationInfo;
28
import android.content.res.Resources;
29
import android.graphics.Bitmap;
30
import android.graphics.Canvas;
31
import android.graphics.Paint;
32
import android.graphics.Paint.Style;
33
import android.opengl.GLSurfaceView;
34

    
35
import org.distorted.library.effect.MatrixEffectScale;
36
import org.distorted.library.main.DistortedEffects;
37
import org.distorted.library.main.DistortedScreen;
38
import org.distorted.library.mesh.MeshSquare;
39
import org.distorted.library.main.DistortedTexture;
40
import org.distorted.library.main.DistortedLibrary;
41
import org.distorted.library.type.Static3D;
42

    
43
import java.io.InputStream;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
class DynamicRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
48
   {  
49
   private final DynamicSurfaceView mView;
50
   private final Resources mResources;
51
   private final DistortedTexture mTexture;
52
   private final DistortedEffects mEffects;
53
   private final DistortedScreen mScreen;
54
   private final MeshSquare mMesh;
55
   private final Paint mPaint;
56
   private final Static3D mScale;
57

    
58
   private Canvas mCanvas;
59
   private Bitmap mBitmap;
60

    
61
   private static int texW, texH;
62
    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
   DynamicRenderer(DynamicSurfaceView v)
66
     {
67
     mView = v;
68
     mResources = v.getResources();
69

    
70
     mPaint = new Paint();
71
     mPaint.setAntiAlias(true);
72
     mPaint.setFakeBoldText(true);
73
     mPaint.setColor(0xff447da7);
74
     mPaint.setStyle(Style.FILL);
75

    
76
     mMesh    = new MeshSquare(1,1);
77
     mScreen  = new DistortedScreen();
78
     mEffects = new DistortedEffects();
79
     mTexture = new DistortedTexture();
80

    
81
     mScale = new Static3D(1,1,1);
82
     mEffects.apply( new MatrixEffectScale(mScale) );
83
     }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
   public void onDrawFrame(GL10 glUnused)
88
     {
89
     long time = System.currentTimeMillis();
90

    
91
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
92
     mView.drawCurve(mCanvas,time);
93
     mTexture.setTexture(mBitmap);
94
     mScreen.render( System.currentTimeMillis() );
95
     }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
100
     {
101
     texW = width;
102
     texH = height;
103

    
104
     mScale.set(width,height,1);
105

    
106
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
107
     mCanvas = new Canvas(mBitmap);
108

    
109
     mScreen.detachAll();
110
     mScreen.attach(mTexture,mEffects,mMesh);
111
     mScreen.resize(texW,texH);
112
     mView.onSurfaceChanged(texW,texH);
113
     DynamicSurfaceView.surfaceChanged(texW,texH);
114
     }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
119
     {
120
     DistortedLibrary.onSurfaceCreated(this);
121
     }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
   public void distortedException(Exception ex)
126
     {
127
     android.util.Log.e("Dynamic", ex.getMessage() );
128
     }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
   public InputStream localFile(int fileID)
133
      {
134
      return mResources.openRawResource(fileID);
135
      }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
   public void logMessage(String message)
140
      {
141
      android.util.Log.e("Dynamic", message );
142
      }
143
  }
(2-2/4)