Project

General

Profile

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

examples / src / main / java / org / distorted / examples / matrix3d / Matrix3DRenderer.java @ 01782e85

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.GLSurfaceView;
23

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

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

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

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

    
39
    private int mWidth, mHeight;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

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

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

    
55
    public void onDrawFrame(GL10 glUnused)
56
      {
57
      mScreen.render( System.currentTimeMillis() );
58
      }
59

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

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

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

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
87
      {
88
      Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
89

    
90
      mTexture.setTexture(act.getBitmap());
91

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