Project

General

Profile

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

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

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