Project

General

Profile

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

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

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 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
import android.graphics.Bitmap;
26
import android.graphics.Canvas;
27
import android.graphics.Paint;
28
import android.graphics.Paint.Style;
29 41a81a14 Leszek Koltunski
import android.opengl.GLES30;
30 427ab7bf Leszek Koltunski
import android.opengl.GLSurfaceView;
31
32 d04a4886 Leszek Koltunski
import org.distorted.library.DistortedEffects;
33 392e16fd Leszek Koltunski
import org.distorted.library.DistortedFramebuffer;
34 d218d64e leszek
import org.distorted.library.DistortedScreen;
35 b01acdaf Leszek Koltunski
import org.distorted.library.MeshFlat;
36 40eef4b9 Leszek Koltunski
import org.distorted.library.DistortedTexture;
37 5068fa06 Leszek Koltunski
import org.distorted.library.Distorted;
38 427ab7bf Leszek Koltunski
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41 97dadfe5 Leszek Koltunski
class DynamicRenderer implements GLSurfaceView.Renderer
42 427ab7bf Leszek Koltunski
   {  
43 fe3c72ce Leszek Koltunski
   private DynamicSurfaceView mView;
44 40eef4b9 Leszek Koltunski
   private DistortedTexture mTexture;
45 d04a4886 Leszek Koltunski
   private DistortedEffects mEffects;
46 d218d64e leszek
   private DistortedScreen mScreen;
47 b01acdaf Leszek Koltunski
   private MeshFlat mMesh;
48 427ab7bf Leszek Koltunski
   private Canvas mCanvas;
49
   private Bitmap mBitmap;
50
   private Paint mPaint;
51 97dadfe5 Leszek Koltunski
52
   static int texW, texH;
53 427ab7bf Leszek Koltunski
    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56 fe3c72ce Leszek Koltunski
   DynamicRenderer(DynamicSurfaceView v)
57 427ab7bf Leszek Koltunski
     {    
58
     mPaint = new Paint();
59
     mPaint.setAntiAlias(true);
60
     mPaint.setFakeBoldText(true);
61
     mPaint.setColor(0xff447da7);
62
     mPaint.setStyle(Style.FILL);
63
      
64 7451c98a Leszek Koltunski
     mView   = v;
65 b01acdaf Leszek Koltunski
     mMesh = new MeshFlat(1,1);
66 d04a4886 Leszek Koltunski
     mEffects = new DistortedEffects();
67 d218d64e leszek
     mScreen = new DistortedScreen();
68 427ab7bf Leszek Koltunski
     }
69
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
   
72
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
73
     {   
74
     try
75 3c8b1903 Leszek Koltunski
       {
76 76f9798b Leszek Koltunski
       Distorted.onCreate(mView.getContext());
77 3c8b1903 Leszek Koltunski
       }
78
     catch(Exception ex)
79
       {
80
       android.util.Log.e("Renderer", ex.getMessage() );
81
       }
82 427ab7bf Leszek Koltunski
     }
83
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
86
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
87
     {
88 97dadfe5 Leszek Koltunski
     texW = width;
89
     texH = height;
90
91 7451c98a Leszek Koltunski
     mTexture= new DistortedTexture(texW,texH);
92 40eef4b9 Leszek Koltunski
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
93
     mCanvas = new Canvas(mBitmap);
94 97dadfe5 Leszek Koltunski
95 392e16fd Leszek Koltunski
     mScreen.resize(texW,texH);
96 fe3c72ce Leszek Koltunski
     mView.onSurfaceChanged(texW,texH);
97 427ab7bf Leszek Koltunski
     }
98
   
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
   
101
   public void onDrawFrame(GL10 glUnused)
102
     {   
103 41a81a14 Leszek Koltunski
     GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT | GLES30.GL_DEPTH_BUFFER_BIT);               
104 427ab7bf Leszek Koltunski
       
105
     long time = System.currentTimeMillis();
106
      
107 97dadfe5 Leszek Koltunski
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
108 fe3c72ce Leszek Koltunski
     mView.drawCurve(mCanvas,time);
109 40eef4b9 Leszek Koltunski
     mTexture.setTexture(mBitmap);
110 b01acdaf Leszek Koltunski
     mScreen.renderTo(mTexture, mMesh, mEffects, System.currentTimeMillis() );
111 427ab7bf Leszek Koltunski
     }
112
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
  }