Project

General

Profile

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

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

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