Project

General

Profile

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

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

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.GLES30;
23
import android.opengl.GLSurfaceView;
24

    
25
import org.distorted.library.Distorted;
26
import org.distorted.library.DistortedScreen;
27
import org.distorted.library.DistortedTexture;
28

    
29
import javax.microedition.khronos.egl.EGLConfig;
30
import javax.microedition.khronos.opengles.GL10;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
class Matrix3DRenderer implements GLSurfaceView.Renderer
35
{
36
    private GLSurfaceView mView;
37
    private DistortedTexture mTexture;
38
    private DistortedScreen mScreen;
39

    
40
    private int mWidth, mHeight;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
    Matrix3DRenderer(GLSurfaceView v)
45
      {
46
      mView = v;
47
      Matrix3DActivity act = (Matrix3DActivity)v.getContext();
48
      mTexture= act.getTexture();
49
      mScreen = new DistortedScreen();
50
      mScreen.attach(mTexture,act.getEffects(),act.getMesh());
51
      }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
    public void onDrawFrame(GL10 glUnused)
56
      {
57
      GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
58
      mScreen.render( System.currentTimeMillis() );
59
      }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
    public int getWidth()
64
      {
65
      return mWidth;
66
      }
67

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

    
70
    public int getHeight()
71
      {
72
      return mHeight;
73
      }
74

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

    
77
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
78
      {
79
      mWidth = width;
80
      mHeight= height;
81

    
82
      mScreen.resize(width, height);
83
      }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
88
      {
89
      GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
90

    
91
      Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
92

    
93
      mTexture.setTexture(act.getBitmap());
94

    
95
      try
96
        {
97
        Distorted.onCreate(mView.getContext());
98
        }
99
      catch(Exception ex)
100
        {
101
        android.util.Log.e("Matrix3D", ex.getMessage() );
102
        }
103
      }
104
}
(3-3/4)