1 |
59835a0a
|
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 |
|
|
|
20 |
|
|
package org.distorted.examples.predeform;
|
21 |
|
|
|
22 |
0dc8ffef
|
Leszek Koltunski
|
import android.graphics.Bitmap;
|
23 |
59835a0a
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
24 |
|
|
|
25 |
|
|
import org.distorted.library.effect.MatrixEffectScale;
|
26 |
|
|
import org.distorted.library.main.DistortedEffects;
|
27 |
|
|
import org.distorted.library.main.DistortedLibrary;
|
28 |
|
|
import org.distorted.library.main.DistortedScreen;
|
29 |
|
|
import org.distorted.library.main.DistortedTexture;
|
30 |
|
|
import org.distorted.library.mesh.MeshBase;
|
31 |
|
|
import org.distorted.library.type.Static3D;
|
32 |
|
|
|
33 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
34 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
35 |
|
|
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
|
|
class PredeformRenderer implements GLSurfaceView.Renderer
|
39 |
|
|
{
|
40 |
0dc8ffef
|
Leszek Koltunski
|
private static final float FOV = 0.0f;
|
41 |
59835a0a
|
Leszek Koltunski
|
private static final float NEAR = 0.1f;
|
42 |
|
|
|
43 |
|
|
private GLSurfaceView mView;
|
44 |
|
|
private DistortedTexture mTexture;
|
45 |
|
|
private DistortedEffects mEffects;
|
46 |
|
|
private MeshBase mMesh;
|
47 |
|
|
private DistortedScreen mScreen;
|
48 |
|
|
private Static3D mScale;
|
49 |
|
|
|
50 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
|
|
PredeformRenderer(GLSurfaceView v)
|
53 |
|
|
{
|
54 |
|
|
mView = v;
|
55 |
|
|
|
56 |
|
|
mScale= new Static3D(1,1,1);
|
57 |
0dc8ffef
|
Leszek Koltunski
|
mTexture = new DistortedTexture();
|
58 |
59835a0a
|
Leszek Koltunski
|
mEffects = new DistortedEffects();
|
59 |
|
|
mEffects.apply( new MatrixEffectScale(mScale));
|
60 |
|
|
|
61 |
|
|
mScreen = new DistortedScreen();
|
62 |
|
|
mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f);
|
63 |
|
|
mScreen.setProjection(FOV, NEAR);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
|
68 |
0dc8ffef
|
Leszek Koltunski
|
void setMesh(MeshBase mesh)
|
69 |
59835a0a
|
Leszek Koltunski
|
{
|
70 |
0dc8ffef
|
Leszek Koltunski
|
mMesh = mesh;
|
71 |
59835a0a
|
Leszek Koltunski
|
}
|
72 |
|
|
|
73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
|
|
|
75 |
0dc8ffef
|
Leszek Koltunski
|
void setTexture(Bitmap bmp)
|
76 |
59835a0a
|
Leszek Koltunski
|
{
|
77 |
0dc8ffef
|
Leszek Koltunski
|
mTexture.setTexture(bmp);
|
78 |
59835a0a
|
Leszek Koltunski
|
}
|
79 |
|
|
|
80 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81 |
|
|
|
82 |
0dc8ffef
|
Leszek Koltunski
|
public void onDrawFrame(GL10 glUnused)
|
83 |
59835a0a
|
Leszek Koltunski
|
{
|
84 |
0dc8ffef
|
Leszek Koltunski
|
mScreen.render( System.currentTimeMillis() );
|
85 |
59835a0a
|
Leszek Koltunski
|
}
|
86 |
|
|
|
87 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88 |
0dc8ffef
|
Leszek Koltunski
|
|
89 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
90 |
59835a0a
|
Leszek Koltunski
|
{
|
91 |
0dc8ffef
|
Leszek Koltunski
|
final float SCALE = 0.75f;
|
92 |
59835a0a
|
Leszek Koltunski
|
|
93 |
0dc8ffef
|
Leszek Koltunski
|
float factor = ( width > height ) ? SCALE*height : SCALE*width;
|
94 |
|
|
mScale.set(factor,factor,factor);
|
95 |
|
|
mScreen.resize(width, height);
|
96 |
59835a0a
|
Leszek Koltunski
|
}
|
97 |
|
|
|
98 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
99 |
|
|
|
100 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
101 |
|
|
{
|
102 |
0dc8ffef
|
Leszek Koltunski
|
PredeformActivity act = (PredeformActivity)mView.getContext();
|
103 |
59835a0a
|
Leszek Koltunski
|
|
104 |
0dc8ffef
|
Leszek Koltunski
|
mMesh = act.getMesh();
|
105 |
59835a0a
|
Leszek Koltunski
|
mTexture.setTexture( act.getBitmap() );
|
106 |
|
|
mScreen.detachAll();
|
107 |
|
|
mScreen.attach(mTexture,mEffects,mMesh);
|
108 |
|
|
|
109 |
|
|
try
|
110 |
|
|
{
|
111 |
|
|
DistortedLibrary.onCreate(act);
|
112 |
|
|
}
|
113 |
|
|
catch(Exception ex)
|
114 |
|
|
{
|
115 |
|
|
android.util.Log.e("Inflate", ex.getMessage() );
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
|
|
}
|