Project

General

Profile

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

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

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.GLSurfaceView;
23 427ab7bf Leszek Koltunski
24 01782e85 Leszek Koltunski
import org.distorted.library.main.Distorted;
25
import org.distorted.library.main.DistortedScreen;
26
import org.distorted.library.main.DistortedTexture;
27 427ab7bf Leszek Koltunski
28 4d5b37fe Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
29
import javax.microedition.khronos.opengles.GL10;
30 427ab7bf Leszek Koltunski
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 db5d943e Leszek Koltunski
class Matrix3DRenderer implements GLSurfaceView.Renderer
34 427ab7bf Leszek Koltunski
{
35
    private GLSurfaceView mView;
36 f6d884d5 Leszek Koltunski
    private DistortedTexture mTexture;
37 d218d64e leszek
    private DistortedScreen mScreen;
38 7589635e Leszek Koltunski
39 334c13fa Leszek Koltunski
    private int mWidth, mHeight;
40
41 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 4d5b37fe Leszek Koltunski
    Matrix3DRenderer(GLSurfaceView v)
44 427ab7bf Leszek Koltunski
      {
45 4d5b37fe Leszek Koltunski
      mView = v;
46 e8b6aa95 Leszek Koltunski
      Matrix3DActivity act = (Matrix3DActivity)v.getContext();
47 f6d884d5 Leszek Koltunski
      mTexture= act.getTexture();
48 1f9a52f1 leszek
      mScreen = new DistortedScreen(mView);
49 fe59d375 Leszek Koltunski
      mScreen.attach(mTexture,act.getEffects(),act.getMesh());
50 89c3e2bf Leszek Koltunski
      mScreen.setProjection(60.0f,0.1f);
51 427ab7bf Leszek Koltunski
      }
52
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
55 4d5b37fe Leszek Koltunski
    public void onDrawFrame(GL10 glUnused)
56 427ab7bf Leszek Koltunski
      {
57 fe59d375 Leszek Koltunski
      mScreen.render( System.currentTimeMillis() );
58 427ab7bf Leszek Koltunski
      }
59
60 334c13fa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62
    public int getWidth()
63
      {
64
      return mWidth;
65
      }
66
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69
    public int getHeight()
70
      {
71
      return mHeight;
72
      }
73
74 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
75
76 4d5b37fe Leszek Koltunski
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
77 427ab7bf Leszek Koltunski
      {
78 334c13fa Leszek Koltunski
      mWidth = width;
79
      mHeight= height;
80
81 392e16fd Leszek Koltunski
      mScreen.resize(width, height);
82 427ab7bf Leszek Koltunski
      }
83
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
86 4d5b37fe Leszek Koltunski
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
87 427ab7bf Leszek Koltunski
      {
88 4d5b37fe Leszek Koltunski
      Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
89
90 f6d884d5 Leszek Koltunski
      mTexture.setTexture(act.getBitmap());
91 4d5b37fe Leszek Koltunski
92 427ab7bf Leszek Koltunski
      try
93
        {
94 76f9798b Leszek Koltunski
        Distorted.onCreate(mView.getContext());
95 427ab7bf Leszek Koltunski
        }
96
      catch(Exception ex)
97
        {
98 08f92d82 Leszek Koltunski
        android.util.Log.e("Matrix3D", ex.getMessage() );
99 427ab7bf Leszek Koltunski
        }
100
      }
101 4d5b37fe Leszek Koltunski
}