Project

General

Profile

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

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

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.DistortedEffects;
27
import org.distorted.library.DistortedFramebuffer;
28
import org.distorted.library.DistortedScreen;
29
import org.distorted.library.MeshObject;
30
import org.distorted.library.DistortedTexture;
31

    
32
import javax.microedition.khronos.egl.EGLConfig;
33
import javax.microedition.khronos.opengles.GL10;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
class Matrix3DRenderer implements GLSurfaceView.Renderer
38
{
39
    private GLSurfaceView mView;
40
    private DistortedTexture mTexture;
41
    private DistortedEffects mEffects;
42
    private DistortedScreen mScreen;
43
    private MeshObject mMesh;
44

    
45
    private int mWidth, mHeight;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
    Matrix3DRenderer(GLSurfaceView v)
50
      {
51
      mView = v;
52

    
53
      Matrix3DActivity act = (Matrix3DActivity)v.getContext();
54

    
55
      mEffects= act.getEffects();
56
      mTexture= act.getTexture();
57
      mMesh = act.getMesh();
58
      mScreen = new DistortedScreen();
59
      }
60

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

    
63
    public void onDrawFrame(GL10 glUnused)
64
      {
65
      GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
66
      mScreen.renderTo(mTexture, mMesh, mEffects, System.currentTimeMillis() );
67
      }
68

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

    
71
    public int getWidth()
72
      {
73
      return mWidth;
74
      }
75

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

    
78
    public int getHeight()
79
      {
80
      return mHeight;
81
      }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
86
      {
87
      mWidth = width;
88
      mHeight= height;
89

    
90
      mScreen.resize(width, height);
91
      }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
96
      {
97
      GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
98

    
99
      Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
100

    
101
      mTexture.setTexture(act.getBitmap());
102

    
103
      try
104
        {
105
        Distorted.onCreate(mView.getContext());
106
        }
107
      catch(Exception ex)
108
        {
109
        android.util.Log.e("Matrix3D", ex.getMessage() );
110
        }
111
      }
112
}
(3-3/4)