Project

General

Profile

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

examples / src / main / java / org / distorted / examples / matrix3d / Matrix3DRenderer.java @ 4d5b37fe

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 4d5b37fe Leszek Koltunski
import org.distorted.library.DistortedObject;
27
import org.distorted.library.EffectTypes;
28 427ab7bf Leszek Koltunski
29 4d5b37fe Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
30
import javax.microedition.khronos.opengles.GL10;
31 427ab7bf Leszek Koltunski
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34 db5d943e Leszek Koltunski
class Matrix3DRenderer implements GLSurfaceView.Renderer
35 427ab7bf Leszek Koltunski
{
36
    private GLSurfaceView mView;
37 4d5b37fe Leszek Koltunski
    private DistortedObject mObject;
38 7589635e Leszek Koltunski
39 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41 4d5b37fe Leszek Koltunski
    Matrix3DRenderer(GLSurfaceView v)
42 427ab7bf Leszek Koltunski
      {
43 4d5b37fe Leszek Koltunski
      mView = v;
44 427ab7bf Leszek Koltunski
45 4d5b37fe Leszek Koltunski
      mObject= ((Matrix3DActivity)v.getContext()).getObject();
46 427ab7bf Leszek Koltunski
      }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50 4d5b37fe Leszek Koltunski
    public void onDrawFrame(GL10 glUnused)
51 427ab7bf Leszek Koltunski
      {
52 4d5b37fe Leszek Koltunski
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
53 427ab7bf Leszek Koltunski
54 4d5b37fe Leszek Koltunski
      long time = System.currentTimeMillis();
55 427ab7bf Leszek Koltunski
56 4d5b37fe Leszek Koltunski
      mObject.draw(time);
57 427ab7bf Leszek Koltunski
      }
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61 4d5b37fe Leszek Koltunski
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
62 427ab7bf Leszek Koltunski
      {
63 4d5b37fe Leszek Koltunski
      mObject.abortEffects(EffectTypes.MATRIX);
64 427ab7bf Leszek Koltunski
65 4d5b37fe Leszek Koltunski
      Distorted.onSurfaceChanged(width, height);
66 427ab7bf Leszek Koltunski
      }
67
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
70 4d5b37fe Leszek Koltunski
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
71 427ab7bf Leszek Koltunski
      {
72 e7a4ef16 Leszek Koltunski
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
73
74 4d5b37fe Leszek Koltunski
      Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
75
76
      mObject.setBitmap( act.getBitmap() );
77
78 427ab7bf Leszek Koltunski
      try
79
        {
80 ed1c0b33 Leszek Koltunski
        Distorted.onSurfaceCreated(mView.getContext());
81 427ab7bf Leszek Koltunski
        }
82
      catch(Exception ex)
83
        {
84 08f92d82 Leszek Koltunski
        android.util.Log.e("Matrix3D", ex.getMessage() );
85 427ab7bf Leszek Koltunski
        }
86
      }
87 4d5b37fe Leszek Koltunski
}