| 1 |
7ba38011
|
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.aroundtheworld;
|
| 21 |
|
|
|
| 22 |
|
|
import android.graphics.Bitmap;
|
| 23 |
|
|
import android.graphics.BitmapFactory;
|
| 24 |
|
|
import android.opengl.GLES20;
|
| 25 |
|
|
import android.opengl.GLSurfaceView;
|
| 26 |
|
|
|
| 27 |
|
|
import org.distorted.examples.R;
|
| 28 |
|
|
import org.distorted.library.Distorted;
|
| 29 |
10b7e588
|
Leszek Koltunski
|
import org.distorted.library.GridFlat;
|
| 30 |
f6d884d5
|
Leszek Koltunski
|
import org.distorted.library.DistortedEffectQueues;
|
| 31 |
|
|
import org.distorted.library.DistortedTexture;
|
| 32 |
7ba38011
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
| 33 |
|
|
import org.distorted.library.type.Static3D;
|
| 34 |
|
|
|
| 35 |
|
|
import java.io.IOException;
|
| 36 |
|
|
import java.io.InputStream;
|
| 37 |
|
|
|
| 38 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
| 39 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
| 40 |
|
|
|
| 41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 42 |
|
|
|
| 43 |
|
|
class AroundTheWorldRenderer implements GLSurfaceView.Renderer
|
| 44 |
|
|
{
|
| 45 |
|
|
private GLSurfaceView mView;
|
| 46 |
f6d884d5
|
Leszek Koltunski
|
private DistortedEffectQueues mQueues;
|
| 47 |
|
|
private DistortedTexture mTexture;
|
| 48 |
10b7e588
|
Leszek Koltunski
|
private GridFlat mGrid;
|
| 49 |
7ba38011
|
Leszek Koltunski
|
private AroundTheWorldEffectsManager mEffects;
|
| 50 |
|
|
private int mObjWidth, mObjHeight;
|
| 51 |
|
|
|
| 52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 53 |
|
|
|
| 54 |
|
|
AroundTheWorldRenderer(GLSurfaceView view)
|
| 55 |
|
|
{
|
| 56 |
b3a555a7
|
Leszek Koltunski
|
Distorted.setMaxVertex(12);
|
| 57 |
287a5475
|
Leszek Koltunski
|
Distorted.setMaxFragment(9);
|
| 58 |
f6d884d5
|
Leszek Koltunski
|
|
| 59 |
|
|
mView = view;
|
| 60 |
|
|
mEffects = new AroundTheWorldEffectsManager();
|
| 61 |
|
|
mQueues = new DistortedEffectQueues();
|
| 62 |
|
|
mEffects.apply(mQueues);
|
| 63 |
7ba38011
|
Leszek Koltunski
|
}
|
| 64 |
|
|
|
| 65 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 66 |
2f20ae3a
|
Leszek Koltunski
|
|
| 67 |
4b34bb08
|
Leszek Koltunski
|
AroundTheWorldEffectsManager getManager()
|
| 68 |
2f20ae3a
|
Leszek Koltunski
|
{
|
| 69 |
|
|
return mEffects;
|
| 70 |
|
|
}
|
| 71 |
|
|
|
| 72 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 73 |
|
|
|
| 74 |
7ba38011
|
Leszek Koltunski
|
public void onDrawFrame(GL10 glUnused)
|
| 75 |
|
|
{
|
| 76 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
| 77 |
f6d884d5
|
Leszek Koltunski
|
mQueues.draw(System.currentTimeMillis(), mTexture, mGrid);
|
| 78 |
7ba38011
|
Leszek Koltunski
|
}
|
| 79 |
|
|
|
| 80 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 81 |
|
|
|
| 82 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
| 83 |
|
|
{
|
| 84 |
f6d884d5
|
Leszek Koltunski
|
mQueues.abortEffects(EffectTypes.MATRIX);
|
| 85 |
7ba38011
|
Leszek Koltunski
|
|
| 86 |
5055b5d4
|
Leszek Koltunski
|
if( (float)mObjHeight/mObjWidth > (float)height/width )
|
| 87 |
7ba38011
|
Leszek Koltunski
|
{
|
| 88 |
|
|
int w = (height*mObjWidth)/mObjHeight;
|
| 89 |
|
|
float factor = (float)height/mObjHeight;
|
| 90 |
f6d884d5
|
Leszek Koltunski
|
mQueues.move( new Static3D((width-w)/2,0,0) );
|
| 91 |
|
|
mQueues.scale(factor);
|
| 92 |
7ba38011
|
Leszek Koltunski
|
}
|
| 93 |
|
|
else
|
| 94 |
|
|
{
|
| 95 |
|
|
int h = (width*mObjHeight)/mObjWidth;
|
| 96 |
|
|
float factor = (float)width/mObjWidth;
|
| 97 |
f6d884d5
|
Leszek Koltunski
|
mQueues.move( new Static3D(0,(height-h)/2,0) );
|
| 98 |
|
|
mQueues.scale(factor);
|
| 99 |
7ba38011
|
Leszek Koltunski
|
}
|
| 100 |
|
|
|
| 101 |
|
|
Distorted.onSurfaceChanged(width, height);
|
| 102 |
|
|
}
|
| 103 |
|
|
|
| 104 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 105 |
|
|
|
| 106 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
| 107 |
e7a4ef16
|
Leszek Koltunski
|
{
|
| 108 |
|
|
GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
| 109 |
|
|
|
| 110 |
7ba38011
|
Leszek Koltunski
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.face);
|
| 111 |
|
|
Bitmap bitmap;
|
| 112 |
|
|
|
| 113 |
|
|
try
|
| 114 |
|
|
{
|
| 115 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
| 116 |
|
|
}
|
| 117 |
|
|
finally
|
| 118 |
|
|
{
|
| 119 |
|
|
try
|
| 120 |
|
|
{
|
| 121 |
|
|
is.close();
|
| 122 |
|
|
}
|
| 123 |
|
|
catch(IOException e) { }
|
| 124 |
|
|
}
|
| 125 |
|
|
|
| 126 |
10b7e588
|
Leszek Koltunski
|
mObjWidth = bitmap.getWidth();
|
| 127 |
|
|
mObjHeight= bitmap.getHeight();
|
| 128 |
7ba38011
|
Leszek Koltunski
|
|
| 129 |
7451c98a
|
Leszek Koltunski
|
mTexture = new DistortedTexture(mObjWidth,mObjHeight);
|
| 130 |
f6d884d5
|
Leszek Koltunski
|
mTexture.setTexture(bitmap);
|
| 131 |
7ba38011
|
Leszek Koltunski
|
|
| 132 |
10b7e588
|
Leszek Koltunski
|
mGrid = new GridFlat(30,30*mObjHeight/mObjWidth);
|
| 133 |
e8b6aa95
|
Leszek Koltunski
|
|
| 134 |
7ba38011
|
Leszek Koltunski
|
try
|
| 135 |
|
|
{
|
| 136 |
|
|
Distorted.onSurfaceCreated(mView.getContext());
|
| 137 |
|
|
}
|
| 138 |
|
|
catch(Exception ex)
|
| 139 |
|
|
{
|
| 140 |
|
|
android.util.Log.e("AroundTheWorld", ex.getMessage() );
|
| 141 |
|
|
}
|
| 142 |
|
|
}
|
| 143 |
|
|
}
|