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 |
427ab7bf
|
Leszek Koltunski
|
}
|
52 |
|
|
|
53 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
|
55 |
4d5b37fe
|
Leszek Koltunski
|
public void onDrawFrame(GL10 glUnused)
|
56 |
427ab7bf
|
Leszek Koltunski
|
{
|
57 |
41a81a14
|
Leszek Koltunski
|
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
|
58 |
fe59d375
|
Leszek Koltunski
|
mScreen.render( System.currentTimeMillis() );
|
59 |
427ab7bf
|
Leszek Koltunski
|
}
|
60 |
|
|
|
61 |
334c13fa
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
|
|
public int getWidth()
|
64 |
|
|
{
|
65 |
|
|
return mWidth;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
|
|
public int getHeight()
|
71 |
|
|
{
|
72 |
|
|
return mHeight;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
|
|
|
77 |
4d5b37fe
|
Leszek Koltunski
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
78 |
427ab7bf
|
Leszek Koltunski
|
{
|
79 |
334c13fa
|
Leszek Koltunski
|
mWidth = width;
|
80 |
|
|
mHeight= height;
|
81 |
|
|
|
82 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(width, height);
|
83 |
427ab7bf
|
Leszek Koltunski
|
}
|
84 |
|
|
|
85 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86 |
|
|
|
87 |
4d5b37fe
|
Leszek Koltunski
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
88 |
427ab7bf
|
Leszek Koltunski
|
{
|
89 |
41a81a14
|
Leszek Koltunski
|
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
90 |
e7a4ef16
|
Leszek Koltunski
|
|
91 |
4d5b37fe
|
Leszek Koltunski
|
Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
|
92 |
|
|
|
93 |
f6d884d5
|
Leszek Koltunski
|
mTexture.setTexture(act.getBitmap());
|
94 |
4d5b37fe
|
Leszek Koltunski
|
|
95 |
427ab7bf
|
Leszek Koltunski
|
try
|
96 |
|
|
{
|
97 |
76f9798b
|
Leszek Koltunski
|
Distorted.onCreate(mView.getContext());
|
98 |
427ab7bf
|
Leszek Koltunski
|
}
|
99 |
|
|
catch(Exception ex)
|
100 |
|
|
{
|
101 |
08f92d82
|
Leszek Koltunski
|
android.util.Log.e("Matrix3D", ex.getMessage() );
|
102 |
427ab7bf
|
Leszek Koltunski
|
}
|
103 |
|
|
}
|
104 |
4d5b37fe
|
Leszek Koltunski
|
}
|