Project

General

Profile

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

examples / src / main / java / org / distorted / examples / matrix3d / Matrix3DRenderer.java @ 392e16fd

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.matrix3d;
21

    
22
import android.opengl.GLES20;
23
import android.opengl.GLSurfaceView;
24

    
25
import org.distorted.library.Distorted;
26
import org.distorted.library.DistortedEffectQueues;
27
import org.distorted.library.DistortedFramebuffer;
28
import org.distorted.library.GridObject;
29
import org.distorted.library.DistortedTexture;
30

    
31
import javax.microedition.khronos.egl.EGLConfig;
32
import javax.microedition.khronos.opengles.GL10;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
class Matrix3DRenderer implements GLSurfaceView.Renderer
37
{
38
    private GLSurfaceView mView;
39
    private DistortedTexture mTexture;
40
    private DistortedEffectQueues mEffects;
41
    private DistortedFramebuffer mScreen;
42
    private GridObject mGrid;
43

    
44
    private int mWidth, mHeight;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
    Matrix3DRenderer(GLSurfaceView v)
49
      {
50
      mView = v;
51

    
52
      Matrix3DActivity act = (Matrix3DActivity)v.getContext();
53

    
54
      mEffects = act.getQueues();
55
      mTexture= act.getTexture();
56
      mGrid   = act.getGrid();
57
      mScreen = new DistortedFramebuffer(0);
58
      }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
    public void onDrawFrame(GL10 glUnused)
63
      {
64
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
65
      mEffects.draw(System.currentTimeMillis(),mTexture,mGrid,mScreen);
66
      }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
    public int getWidth()
71
      {
72
      return mWidth;
73
      }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
    public int getHeight()
78
      {
79
      return mHeight;
80
      }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
85
      {
86
      mWidth = width;
87
      mHeight= height;
88

    
89
      mScreen.resize(width, height);
90
      }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
95
      {
96
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
97

    
98
      Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
99

    
100
      mTexture.setTexture(act.getBitmap());
101

    
102
      try
103
        {
104
        Distorted.onSurfaceCreated(mView.getContext());
105
        }
106
      catch(Exception ex)
107
        {
108
        android.util.Log.e("Matrix3D", ex.getMessage() );
109
        }
110
      }
111
}
(3-3/4)