Project

General

Profile

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

examples / src / main / java / org / distorted / examples / matrix3d / Matrix3DRenderer.java @ 89c3e2bf

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
      mScreen.setProjection(60.0f,0.1f);
52
      }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

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

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

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

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

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

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

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

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

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

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

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

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

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