Project

General

Profile

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

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

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 71c8884f Leszek Koltunski
// This file is part of Distorted.                                                               //
5 bc0a685b Leszek Koltunski
//                                                                                               //
6 71c8884f Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 bc0a685b Leszek Koltunski
// 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 71c8884f Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 bc0a685b Leszek Koltunski
// 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 71c8884f Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 f988589e Leszek Koltunski
package org.distorted.examples.dynamic;
21 427ab7bf Leszek Koltunski
22
import javax.microedition.khronos.egl.EGLConfig;
23
import javax.microedition.khronos.opengles.GL10;
24
25 dc10a48d Leszek Koltunski
import android.app.ActivityManager;
26
import android.content.Context;
27
import android.content.pm.ConfigurationInfo;
28
import android.content.res.Resources;
29 427ab7bf Leszek Koltunski
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 1fc23462 Leszek Koltunski
import org.distorted.library.effect.MatrixEffectScale;
36 01782e85 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
37
import org.distorted.library.main.DistortedScreen;
38 f2085b96 Leszek Koltunski
import org.distorted.library.mesh.MeshSquare;
39 01782e85 Leszek Koltunski
import org.distorted.library.main.DistortedTexture;
40 e3900503 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
41 1fc23462 Leszek Koltunski
import org.distorted.library.type.Static3D;
42 427ab7bf Leszek Koltunski
43 dc10a48d Leszek Koltunski
import java.io.InputStream;
44
45 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
46
47 dc10a48d Leszek Koltunski
class DynamicRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
48 427ab7bf Leszek Koltunski
   {  
49 dc10a48d Leszek Koltunski
   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 427ab7bf Leszek Koltunski
   private Canvas mCanvas;
59
   private Bitmap mBitmap;
60 dc10a48d Leszek Koltunski
61 2666a48c Leszek Koltunski
   private static int texW, texH;
62 427ab7bf Leszek Koltunski
    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
65 fe3c72ce Leszek Koltunski
   DynamicRenderer(DynamicSurfaceView v)
66 dc10a48d Leszek Koltunski
     {
67
     mView = v;
68
     mResources = v.getResources();
69
70 427ab7bf Leszek Koltunski
     mPaint = new Paint();
71
     mPaint.setAntiAlias(true);
72
     mPaint.setFakeBoldText(true);
73
     mPaint.setColor(0xff447da7);
74
     mPaint.setStyle(Style.FILL);
75 dc10a48d Leszek Koltunski
76 f2085b96 Leszek Koltunski
     mMesh    = new MeshSquare(1,1);
77 e4330c89 Leszek Koltunski
     mScreen  = new DistortedScreen();
78 698ad0a8 Leszek Koltunski
     mEffects = new DistortedEffects();
79 1fc23462 Leszek Koltunski
     mTexture = new DistortedTexture();
80
81
     mScale = new Static3D(1,1,1);
82
     mEffects.apply( new MatrixEffectScale(mScale) );
83 427ab7bf Leszek Koltunski
     }
84
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86 061449ed Leszek Koltunski
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 427ab7bf Leszek Koltunski
     }
96
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
100
     {
101 97dadfe5 Leszek Koltunski
     texW = width;
102
     texH = height;
103
104 1fc23462 Leszek Koltunski
     mScale.set(width,height,1);
105 2666a48c Leszek Koltunski
106 40eef4b9 Leszek Koltunski
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
107
     mCanvas = new Canvas(mBitmap);
108 97dadfe5 Leszek Koltunski
109 fe59d375 Leszek Koltunski
     mScreen.detachAll();
110
     mScreen.attach(mTexture,mEffects,mMesh);
111 392e16fd Leszek Koltunski
     mScreen.resize(texW,texH);
112 fe3c72ce Leszek Koltunski
     mView.onSurfaceChanged(texW,texH);
113 1fc23462 Leszek Koltunski
     DynamicSurfaceView.surfaceChanged(texW,texH);
114 427ab7bf Leszek Koltunski
     }
115 061449ed Leszek Koltunski
116 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
117 061449ed Leszek Koltunski
118
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
119
     {
120 dc10a48d Leszek Koltunski
     DistortedLibrary.onSurfaceCreated(this);
121 061449ed Leszek Koltunski
     }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125
   public void distortedException(Exception ex)
126
     {
127
     android.util.Log.e("Dynamic", ex.getMessage() );
128 427ab7bf Leszek Koltunski
     }
129 dc10a48d Leszek Koltunski
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 427ab7bf Leszek Koltunski
  }