Project

General

Profile

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

examples / src / main / java / org / distorted / examples / matrix3d / Matrix3DRenderer.java @ f6d884d5

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 427ab7bf Leszek Koltunski
20 db5d943e Leszek Koltunski
package org.distorted.examples.matrix3d;
21 427ab7bf Leszek Koltunski
22 4d5b37fe Leszek Koltunski
import android.opengl.GLES20;
23
import android.opengl.GLSurfaceView;
24 427ab7bf Leszek Koltunski
25 5068fa06 Leszek Koltunski
import org.distorted.library.Distorted;
26 f6d884d5 Leszek Koltunski
import org.distorted.library.DistortedEffectQueues;
27 10b7e588 Leszek Koltunski
import org.distorted.library.GridObject;
28 f6d884d5 Leszek Koltunski
import org.distorted.library.DistortedTexture;
29 4d5b37fe Leszek Koltunski
import org.distorted.library.EffectTypes;
30 427ab7bf Leszek Koltunski
31 4d5b37fe Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
32
import javax.microedition.khronos.opengles.GL10;
33 427ab7bf Leszek Koltunski
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 db5d943e Leszek Koltunski
class Matrix3DRenderer implements GLSurfaceView.Renderer
37 427ab7bf Leszek Koltunski
{
38
    private GLSurfaceView mView;
39 f6d884d5 Leszek Koltunski
    private DistortedTexture mTexture;
40
    private DistortedEffectQueues mQueues;
41 10b7e588 Leszek Koltunski
    private GridObject mGrid;
42 7589635e Leszek Koltunski
43 334c13fa Leszek Koltunski
    private int mWidth, mHeight;
44
45 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
46
47 4d5b37fe Leszek Koltunski
    Matrix3DRenderer(GLSurfaceView v)
48 427ab7bf Leszek Koltunski
      {
49 4d5b37fe Leszek Koltunski
      mView = v;
50 427ab7bf Leszek Koltunski
51 e8b6aa95 Leszek Koltunski
      Matrix3DActivity act = (Matrix3DActivity)v.getContext();
52
53 f6d884d5 Leszek Koltunski
      mQueues = act.getQueues();
54
      mTexture= act.getTexture();
55
      mGrid   = act.getGrid();
56 427ab7bf Leszek Koltunski
      }
57
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59
60 4d5b37fe Leszek Koltunski
    public void onDrawFrame(GL10 glUnused)
61 427ab7bf Leszek Koltunski
      {
62 4d5b37fe Leszek Koltunski
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
63 f6d884d5 Leszek Koltunski
      mQueues.draw(System.currentTimeMillis(),mTexture,mGrid);
64 427ab7bf Leszek Koltunski
      }
65
66 334c13fa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
67
68
    public int getWidth()
69
      {
70
      return mWidth;
71
      }
72
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
75
    public int getHeight()
76
      {
77
      return mHeight;
78
      }
79
80 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
81
82 4d5b37fe Leszek Koltunski
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
83 427ab7bf Leszek Koltunski
      {
84 f6d884d5 Leszek Koltunski
      mQueues.abortEffects(EffectTypes.MATRIX);
85 427ab7bf Leszek Koltunski
86 334c13fa Leszek Koltunski
      mWidth = width;
87
      mHeight= height;
88
89 4d5b37fe Leszek Koltunski
      Distorted.onSurfaceChanged(width, height);
90 427ab7bf Leszek Koltunski
      }
91
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
94 4d5b37fe Leszek Koltunski
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
95 427ab7bf Leszek Koltunski
      {
96 e7a4ef16 Leszek Koltunski
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
97
98 4d5b37fe Leszek Koltunski
      Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
99
100 f6d884d5 Leszek Koltunski
      mTexture.setTexture(act.getBitmap());
101 4d5b37fe Leszek Koltunski
102 427ab7bf Leszek Koltunski
      try
103
        {
104 ed1c0b33 Leszek Koltunski
        Distorted.onSurfaceCreated(mView.getContext());
105 427ab7bf Leszek Koltunski
        }
106
      catch(Exception ex)
107
        {
108 08f92d82 Leszek Koltunski
        android.util.Log.e("Matrix3D", ex.getMessage() );
109 427ab7bf Leszek Koltunski
        }
110
      }
111 4d5b37fe Leszek Koltunski
}