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