Revision 664a0e45
Added by Leszek Koltunski over 7 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 46 | 46 |
<activity android:name=".blur.BlurActivity"/> |
| 47 | 47 |
<activity android:name=".multiblur.MultiblurActivity"/> |
| 48 | 48 |
<activity android:name=".triblur.TriblurActivity"/> |
| 49 |
<activity android:name=".transparency.TransparencyActivity"/> |
|
| 49 | 50 |
<activity android:name=".postprocesstree.PostprocessTreeActivity"/> |
| 50 | 51 |
<activity android:name=".stencil.StencilActivity"/> |
| 51 | 52 |
<activity android:name=".glow.GlowActivity"/> |
| src/main/java/org/distorted/examples/TableOfContents.java | ||
|---|---|---|
| 64 | 64 |
import org.distorted.examples.blur.BlurActivity; |
| 65 | 65 |
import org.distorted.examples.multiblur.MultiblurActivity; |
| 66 | 66 |
import org.distorted.examples.triblur.TriblurActivity; |
| 67 |
import org.distorted.examples.transparency.TransparencyActivity; |
|
| 67 | 68 |
import org.distorted.examples.postprocesstree.PostprocessTreeActivity; |
| 68 | 69 |
import org.distorted.examples.stencil.StencilActivity; |
| 69 | 70 |
import org.distorted.examples.glow.GlowActivity; |
| ... | ... | |
| 360 | 361 |
activityMapping.put(i++, TriblurActivity.class); |
| 361 | 362 |
} |
| 362 | 363 |
|
| 364 |
{
|
|
| 365 |
final Map<String, Object> item = new HashMap<>(); |
|
| 366 |
item.put(ITEM_IMAGE, R.drawable.icon_example_transparency); |
|
| 367 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_transparency)); |
|
| 368 |
item.put(ITEM_SUBTITLE, getText(R.string.example_transparency_subtitle)); |
|
| 369 |
data.add(item); |
|
| 370 |
activityMapping.put(i++, TransparencyActivity.class); |
|
| 371 |
} |
|
| 372 |
|
|
| 363 | 373 |
{
|
| 364 | 374 |
final Map<String, Object> item = new HashMap<>(); |
| 365 | 375 |
item.put(ITEM_IMAGE, R.drawable.icon_example_postprocesstree); |
| src/main/java/org/distorted/examples/transparency/TransparencyActivity.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 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.transparency; |
|
| 21 |
|
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.view.View; |
|
| 26 |
import android.widget.SeekBar; |
|
| 27 |
|
|
| 28 |
import org.distorted.examples.R; |
|
| 29 |
import org.distorted.library.main.Distorted; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
public class TransparencyActivity extends Activity implements SeekBar.OnSeekBarChangeListener |
|
| 34 |
{
|
|
| 35 |
private int mRenderFirst; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
@Override |
|
| 40 |
protected void onCreate(Bundle savedState) |
|
| 41 |
{
|
|
| 42 |
super.onCreate(savedState); |
|
| 43 |
setContentView(R.layout.transparencylayout); |
|
| 44 |
|
|
| 45 |
SeekBar barRed = (SeekBar)findViewById(R.id.transparencySeekRed); |
|
| 46 |
SeekBar barYellow = (SeekBar)findViewById(R.id.transparencySeekYellow); |
|
| 47 |
|
|
| 48 |
barRed.setOnSeekBarChangeListener(this); |
|
| 49 |
barYellow.setOnSeekBarChangeListener(this); |
|
| 50 |
|
|
| 51 |
if( savedState==null ) |
|
| 52 |
{
|
|
| 53 |
barRed.setProgress(50); |
|
| 54 |
barYellow.setProgress(50); |
|
| 55 |
privateRenderFirst(0); |
|
| 56 |
} |
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
@Override |
|
| 62 |
protected void onPause() |
|
| 63 |
{
|
|
| 64 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.transparencySurfaceView); |
|
| 65 |
view.onPause(); |
|
| 66 |
Distorted.onPause(); |
|
| 67 |
super.onPause(); |
|
| 68 |
} |
|
| 69 |
|
|
| 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 71 |
|
|
| 72 |
@Override |
|
| 73 |
protected void onResume() |
|
| 74 |
{
|
|
| 75 |
super.onResume(); |
|
| 76 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.transparencySurfaceView); |
|
| 77 |
view.onResume(); |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
@Override |
|
| 83 |
protected void onDestroy() |
|
| 84 |
{
|
|
| 85 |
Distorted.onDestroy(); |
|
| 86 |
super.onDestroy(); |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 90 |
|
|
| 91 |
@Override |
|
| 92 |
public void onSaveInstanceState(Bundle savedInstanceState) |
|
| 93 |
{
|
|
| 94 |
super.onSaveInstanceState(savedInstanceState); |
|
| 95 |
savedInstanceState.putInt("render", mRenderFirst);
|
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
@Override |
|
| 101 |
public void onRestoreInstanceState(Bundle savedInstanceState) |
|
| 102 |
{
|
|
| 103 |
super.onRestoreInstanceState(savedInstanceState); |
|
| 104 |
|
|
| 105 |
mRenderFirst= savedInstanceState.getInt("render");
|
|
| 106 |
privateRenderFirst(mRenderFirst); |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 |
|
|
| 111 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
| 112 |
{
|
|
| 113 |
switch (bar.getId()) |
|
| 114 |
{
|
|
| 115 |
case R.id.transparencySeekRed: TransparencySurfaceView view0 = (TransparencySurfaceView) this.findViewById(R.id.transparencySurfaceView); |
|
| 116 |
view0.getRenderer().setTransparency(0, (float)progress/100 ); |
|
| 117 |
break; |
|
| 118 |
case R.id.transparencySeekYellow: TransparencySurfaceView view1 = (TransparencySurfaceView) this.findViewById(R.id.transparencySurfaceView); |
|
| 119 |
view1.getRenderer().setTransparency(1, (float)progress/100 ); |
|
| 120 |
break; |
|
| 121 |
} |
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 125 |
|
|
| 126 |
public void onStartTrackingTouch(SeekBar bar) { }
|
|
| 127 |
|
|
| 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 129 |
|
|
| 130 |
public void onStopTrackingTouch(SeekBar bar) { }
|
|
| 131 |
|
|
| 132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 133 |
|
|
| 134 |
public void renderFirst(View v) |
|
| 135 |
{
|
|
| 136 |
switch(v.getId()) |
|
| 137 |
{
|
|
| 138 |
case R.id.transparencyRed : privateRenderFirst(0); break; |
|
| 139 |
case R.id.transparencyYellow: privateRenderFirst(1); break; |
|
| 140 |
} |
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 144 |
|
|
| 145 |
private void privateRenderFirst(int index) |
|
| 146 |
{
|
|
| 147 |
TransparencySurfaceView view = (TransparencySurfaceView) this.findViewById(R.id.transparencySurfaceView); |
|
| 148 |
TransparencyRenderer renderer= view.getRenderer(); |
|
| 149 |
|
|
| 150 |
renderer.setRenderFirst(index); |
|
| 151 |
mRenderFirst = index; |
|
| 152 |
} |
|
| 153 |
} |
|
| src/main/java/org/distorted/examples/transparency/TransparencyRenderer.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 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.transparency; |
|
| 21 |
|
|
| 22 |
import android.opengl.GLSurfaceView; |
|
| 23 |
|
|
| 24 |
import org.distorted.library.effect.FragmentEffectAlpha; |
|
| 25 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 26 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
| 27 |
import org.distorted.library.effect.MatrixEffectScale; |
|
| 28 |
import org.distorted.library.effect.PostprocessEffectBlur; |
|
| 29 |
import org.distorted.library.main.Distorted; |
|
| 30 |
import org.distorted.library.main.DistortedEffects; |
|
| 31 |
import org.distorted.library.main.DistortedNode; |
|
| 32 |
import org.distorted.library.main.DistortedScreen; |
|
| 33 |
import org.distorted.library.main.DistortedTexture; |
|
| 34 |
import org.distorted.library.main.MeshFlat; |
|
| 35 |
import org.distorted.library.type.Static1D; |
|
| 36 |
import org.distorted.library.type.Static3D; |
|
| 37 |
import org.distorted.library.type.Static4D; |
|
| 38 |
|
|
| 39 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 40 |
import javax.microedition.khronos.opengles.GL10; |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
class TransparencyRenderer implements GLSurfaceView.Renderer |
|
| 45 |
{
|
|
| 46 |
private static final int NUM = 4; // 4 ints (x,y,z, argb) each describe 1 object below |
|
| 47 |
|
|
| 48 |
private static final int[] OBJECTS = |
|
| 49 |
{
|
|
| 50 |
+9, -10, +2, 0xffff0000, |
|
| 51 |
-9, +10, -2, 0xffffff00 |
|
| 52 |
}; |
|
| 53 |
|
|
| 54 |
private static final int NUM_OBJECTS = OBJECTS.length/NUM; |
|
| 55 |
private static final int OBJ_SIZE = 100; |
|
| 56 |
|
|
| 57 |
private GLSurfaceView mView; |
|
| 58 |
private DistortedNode[] mNode; |
|
| 59 |
private DistortedTexture[] mTex; |
|
| 60 |
private Static3D[] mMoveVector; |
|
| 61 |
private Static1D[] mAlphaVector; |
|
| 62 |
private DistortedScreen mScreen; |
|
| 63 |
private Static3D mMove, mScale, mCenter; |
|
| 64 |
|
|
| 65 |
Static4D mQuat1, mQuat2; |
|
| 66 |
int mScreenMin; |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
|
|
| 70 |
TransparencyRenderer(GLSurfaceView v) |
|
| 71 |
{
|
|
| 72 |
mView = v; |
|
| 73 |
|
|
| 74 |
MeshFlat mesh = new MeshFlat(1,1); |
|
| 75 |
|
|
| 76 |
mQuat1 = new Static4D(0,0,0,1); // unity |
|
| 77 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
|
| 78 |
|
|
| 79 |
mScreen = new DistortedScreen(); |
|
| 80 |
mScreen.glClearColor(1.0f,1.0f,1.0f,1.0f); |
|
| 81 |
|
|
| 82 |
mMoveVector = new Static3D[NUM_OBJECTS]; |
|
| 83 |
mAlphaVector = new Static1D[NUM_OBJECTS]; |
|
| 84 |
mNode = new DistortedNode[NUM_OBJECTS]; |
|
| 85 |
mTex = new DistortedTexture[NUM_OBJECTS]; |
|
| 86 |
|
|
| 87 |
FragmentEffectAlpha[] alpha= new FragmentEffectAlpha[NUM_OBJECTS]; |
|
| 88 |
DistortedEffects[] effects = new DistortedEffects[NUM_OBJECTS]; |
|
| 89 |
|
|
| 90 |
mMove = new Static3D(0,0,0); |
|
| 91 |
mScale = new Static3D(1.0f,1.0f,1.0f); |
|
| 92 |
mCenter= new Static3D(0,0,0); |
|
| 93 |
|
|
| 94 |
MatrixEffectMove moveEffect = new MatrixEffectMove(mMove); |
|
| 95 |
MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale); |
|
| 96 |
MatrixEffectQuaternion quatEffect1 = new MatrixEffectQuaternion(mQuat1, mCenter); |
|
| 97 |
MatrixEffectQuaternion quatEffect2 = new MatrixEffectQuaternion(mQuat2, mCenter); |
|
| 98 |
|
|
| 99 |
PostprocessEffectBlur blur = new PostprocessEffectBlur(new Static1D(0)); |
|
| 100 |
|
|
| 101 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 102 |
{
|
|
| 103 |
mTex[i] = new DistortedTexture(OBJ_SIZE,OBJ_SIZE); |
|
| 104 |
mMoveVector[i] = new Static3D(0,0,0); |
|
| 105 |
mAlphaVector[i] = new Static1D(0.5f); |
|
| 106 |
alpha[i] = new FragmentEffectAlpha(mAlphaVector[i]); |
|
| 107 |
effects[i] = new DistortedEffects(); |
|
| 108 |
|
|
| 109 |
//effects[i].apply(blur); |
|
| 110 |
effects[i].apply(alpha[i]); |
|
| 111 |
effects[i].apply(moveEffect); |
|
| 112 |
effects[i].apply(scaleEffect); |
|
| 113 |
effects[i].apply(quatEffect1); |
|
| 114 |
effects[i].apply(quatEffect2); |
|
| 115 |
effects[i].apply(new MatrixEffectMove(mMoveVector[i])); |
|
| 116 |
|
|
| 117 |
mNode[i] = new DistortedNode(mTex[i], effects[i], mesh ); |
|
| 118 |
mScreen.attach(mNode[i]); |
|
| 119 |
} |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 123 |
|
|
| 124 |
void setTransparency(int object, float level) |
|
| 125 |
{
|
|
| 126 |
if( object>=0 && object<NUM_OBJECTS) mAlphaVector[object].set(level); |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
// no better way to attach mNode[object] as the first child than detaching all and reattaching back... |
|
| 131 |
|
|
| 132 |
void setRenderFirst(int object) |
|
| 133 |
{
|
|
| 134 |
if( object>=0 && object<NUM_OBJECTS) |
|
| 135 |
{
|
|
| 136 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 137 |
{
|
|
| 138 |
mScreen.detach(mNode[i]); |
|
| 139 |
} |
|
| 140 |
|
|
| 141 |
mScreen.attach(mNode[object]); |
|
| 142 |
|
|
| 143 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 144 |
{
|
|
| 145 |
if( i!=object ) |
|
| 146 |
mScreen.attach(mNode[i]); |
|
| 147 |
} |
|
| 148 |
} |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 152 |
|
|
| 153 |
public void onDrawFrame(GL10 glUnused) |
|
| 154 |
{
|
|
| 155 |
mScreen.render(System.currentTimeMillis()); |
|
| 156 |
} |
|
| 157 |
|
|
| 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 159 |
|
|
| 160 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 161 |
{
|
|
| 162 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 163 |
{
|
|
| 164 |
mTex[i].setColor(OBJECTS[NUM * i + 3]); |
|
| 165 |
} |
|
| 166 |
|
|
| 167 |
PostprocessEffectBlur.enable(); |
|
| 168 |
FragmentEffectAlpha.enable(); |
|
| 169 |
|
|
| 170 |
try |
|
| 171 |
{
|
|
| 172 |
Distorted.onCreate(mView.getContext()); |
|
| 173 |
} |
|
| 174 |
catch(Exception ex) |
|
| 175 |
{
|
|
| 176 |
android.util.Log.e("Transparency", ex.getMessage() );
|
|
| 177 |
} |
|
| 178 |
} |
|
| 179 |
|
|
| 180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 181 |
|
|
| 182 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 183 |
{
|
|
| 184 |
mScreenMin = width<height ? width:height; |
|
| 185 |
|
|
| 186 |
float factor = 0.70f*mScreenMin/OBJ_SIZE; |
|
| 187 |
mScale.set(factor,factor,factor); |
|
| 188 |
mCenter.set((float)OBJ_SIZE/2, (float)OBJ_SIZE/2, -(float)OBJ_SIZE/2 ); |
|
| 189 |
mMove.set( (width -factor*OBJ_SIZE)/2 ,(height-factor*OBJ_SIZE)/2 ,0); |
|
| 190 |
|
|
| 191 |
float size= 0.02f*OBJ_SIZE; |
|
| 192 |
|
|
| 193 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 194 |
{
|
|
| 195 |
mMoveVector[i].set(size*OBJECTS[NUM*i], size*OBJECTS[NUM*i+1], size*OBJECTS[NUM*i+2]); |
|
| 196 |
} |
|
| 197 |
|
|
| 198 |
mScreen.resize(width, height); |
|
| 199 |
} |
|
| 200 |
} |
|
| src/main/java/org/distorted/examples/transparency/TransparencySurfaceView.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 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.transparency; |
|
| 21 |
|
|
| 22 |
import android.app.ActivityManager; |
|
| 23 |
import android.content.Context; |
|
| 24 |
import android.content.pm.ConfigurationInfo; |
|
| 25 |
import android.opengl.GLSurfaceView; |
|
| 26 |
import android.util.AttributeSet; |
|
| 27 |
import android.view.MotionEvent; |
|
| 28 |
import android.widget.Toast; |
|
| 29 |
|
|
| 30 |
import org.distorted.examples.R; |
|
| 31 |
|
|
| 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 33 |
|
|
| 34 |
class TransparencySurfaceView extends GLSurfaceView |
|
| 35 |
{
|
|
| 36 |
private int mX, mY; |
|
| 37 |
private TransparencyRenderer mRenderer; |
|
| 38 |
|
|
| 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 40 |
|
|
| 41 |
public TransparencySurfaceView(Context context, AttributeSet attrs) |
|
| 42 |
{
|
|
| 43 |
super(context, attrs); |
|
| 44 |
|
|
| 45 |
mX = -1; |
|
| 46 |
mY = -1; |
|
| 47 |
|
|
| 48 |
if(!isInEditMode()) |
|
| 49 |
{
|
|
| 50 |
mRenderer = new TransparencyRenderer(this); |
|
| 51 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 52 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 53 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
| 54 |
setRenderer(mRenderer); |
|
| 55 |
Toast.makeText(context, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show(); |
|
| 56 |
} |
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
public TransparencyRenderer getRenderer() |
|
| 62 |
{
|
|
| 63 |
return mRenderer; |
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 67 |
|
|
| 68 |
@Override public boolean onTouchEvent(MotionEvent event) |
|
| 69 |
{
|
|
| 70 |
int action = event.getAction(); |
|
| 71 |
int x = (int)event.getX(); |
|
| 72 |
int y = (int)event.getY(); |
|
| 73 |
|
|
| 74 |
switch(action) |
|
| 75 |
{
|
|
| 76 |
case MotionEvent.ACTION_DOWN: mX = x; |
|
| 77 |
mY = y; |
|
| 78 |
break; |
|
| 79 |
|
|
| 80 |
case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 ) |
|
| 81 |
{
|
|
| 82 |
float px = mY-y; |
|
| 83 |
float py = mX-x; |
|
| 84 |
float pz = 0; |
|
| 85 |
float plen = (float)Math.sqrt(px*px + py*py + pz*pz); |
|
| 86 |
|
|
| 87 |
if( plen>0 ) |
|
| 88 |
{
|
|
| 89 |
px /= plen; |
|
| 90 |
py /= plen; |
|
| 91 |
pz /= plen; |
|
| 92 |
|
|
| 93 |
float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin); |
|
| 94 |
float sinA = (float)Math.sqrt(1-cosA*cosA); |
|
| 95 |
|
|
| 96 |
mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA); |
|
| 97 |
} |
|
| 98 |
} |
|
| 99 |
break; |
|
| 100 |
|
|
| 101 |
case MotionEvent.ACTION_UP : mX = -1; |
|
| 102 |
mY = -1; |
|
| 103 |
|
|
| 104 |
float qx = mRenderer.mQuat1.get1(); |
|
| 105 |
float qy = mRenderer.mQuat1.get2(); |
|
| 106 |
float qz = mRenderer.mQuat1.get3(); |
|
| 107 |
float qw = mRenderer.mQuat1.get4(); |
|
| 108 |
|
|
| 109 |
float rx = mRenderer.mQuat2.get1(); |
|
| 110 |
float ry = mRenderer.mQuat2.get2(); |
|
| 111 |
float rz = mRenderer.mQuat2.get3(); |
|
| 112 |
float rw = mRenderer.mQuat2.get4(); |
|
| 113 |
|
|
| 114 |
// This is quaternion multiplication. (tx,ty,tz,tw) |
|
| 115 |
// is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw) |
|
| 116 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
| 117 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
| 118 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
| 119 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
| 120 |
|
|
| 121 |
// The point of this is so that there are always |
|
| 122 |
// exactly 2 quaternions: Quat1 representing the rotation |
|
| 123 |
// accumulating only since the last screen touch, and Quat2 |
|
| 124 |
// which remembers the combined effect of all previous |
|
| 125 |
// swipes. |
|
| 126 |
// We cannot be accumulating an ever-growing list of quaternions |
|
| 127 |
// and add a new one every time user swipes the screen - there |
|
| 128 |
// is a limited number of slots in the EffectQueueMatrix! |
|
| 129 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
| 130 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
| 131 |
|
|
| 132 |
break; |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
return true; |
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
} |
|
| 139 |
|
|
| src/main/res/layout/transparencylayout.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:layout_width="fill_parent" |
|
| 4 |
android:layout_height="fill_parent" |
|
| 5 |
android:orientation="vertical" > |
|
| 6 |
|
|
| 7 |
<org.distorted.examples.transparency.TransparencySurfaceView |
|
| 8 |
android:id="@+id/transparencySurfaceView" |
|
| 9 |
android:layout_width="fill_parent" |
|
| 10 |
android:layout_height="0dp" |
|
| 11 |
android:layout_weight="1" /> |
|
| 12 |
|
|
| 13 |
<LinearLayout |
|
| 14 |
android:id="@+id/linearLayout1" |
|
| 15 |
android:layout_width="fill_parent" |
|
| 16 |
android:layout_height="100dp" |
|
| 17 |
android:orientation="horizontal"> |
|
| 18 |
|
|
| 19 |
<LinearLayout |
|
| 20 |
android:id="@+id/linearLayout2" |
|
| 21 |
android:layout_width="wrap_content" |
|
| 22 |
android:layout_height="fill_parent" |
|
| 23 |
android:orientation="vertical" |
|
| 24 |
android:layout_weight="0.1"> |
|
| 25 |
|
|
| 26 |
<RadioGroup |
|
| 27 |
android:id="@+id/transparencyRadioGroup" |
|
| 28 |
android:layout_width="fill_parent" |
|
| 29 |
android:layout_height="fill_parent" |
|
| 30 |
android:orientation="vertical"> |
|
| 31 |
|
|
| 32 |
<RadioButton |
|
| 33 |
android:id="@+id/transparencyRed" |
|
| 34 |
android:layout_width="fill_parent" |
|
| 35 |
android:layout_height="wrap_content" |
|
| 36 |
android:layout_weight="1" |
|
| 37 |
android:background="@color/red" |
|
| 38 |
android:onClick="renderFirst" |
|
| 39 |
android:checked="true" |
|
| 40 |
android:textSize="14sp"/> |
|
| 41 |
|
|
| 42 |
<RadioButton |
|
| 43 |
android:id="@+id/transparencyYellow" |
|
| 44 |
android:layout_width="fill_parent" |
|
| 45 |
android:layout_height="wrap_content" |
|
| 46 |
android:layout_weight="1" |
|
| 47 |
android:background="@color/yellow" |
|
| 48 |
android:onClick="renderFirst" |
|
| 49 |
android:textSize="14sp"/> |
|
| 50 |
</RadioGroup> |
|
| 51 |
</LinearLayout> |
|
| 52 |
|
|
| 53 |
<LinearLayout |
|
| 54 |
android:id="@+id/linearLayout3" |
|
| 55 |
android:layout_width="wrap_content" |
|
| 56 |
android:layout_height="fill_parent" |
|
| 57 |
android:orientation="vertical" |
|
| 58 |
android:layout_weight="0.9"> |
|
| 59 |
|
|
| 60 |
<SeekBar |
|
| 61 |
android:id="@+id/transparencySeekRed" |
|
| 62 |
android:background="@color/red" |
|
| 63 |
android:layout_height="50dp" |
|
| 64 |
android:layout_width="fill_parent" |
|
| 65 |
android:paddingLeft="10dp" |
|
| 66 |
android:paddingRight="10dp" /> |
|
| 67 |
<SeekBar |
|
| 68 |
android:id="@+id/transparencySeekYellow" |
|
| 69 |
android:background="@color/yellow" |
|
| 70 |
android:layout_height="50dp" |
|
| 71 |
android:layout_width="fill_parent" |
|
| 72 |
android:paddingLeft="10dp" |
|
| 73 |
android:paddingRight="10dp" /> |
|
| 74 |
|
|
| 75 |
</LinearLayout> |
|
| 76 |
</LinearLayout> |
|
| 77 |
</LinearLayout> |
|
| src/main/res/values/strings.xml | ||
|---|---|---|
| 159 | 159 |
<string name="example_triblur_subtitle">Three different, blurred, obstructing objects.</string> |
| 160 | 160 |
<string name="example_postprocesstree">Postprocess Tree</string> |
| 161 | 161 |
<string name="example_postprocesstree_subtitle">Three layers of postprocessed surfaces.</string> |
| 162 |
<string name="example_transparency">Transparency</string> |
|
| 163 |
<string name="example_transparency_subtitle">Order Independent Transparency.</string> |
|
| 162 | 164 |
<string name="example_stencil">Stencil Buffer</string> |
| 163 | 165 |
<string name="example_stencil_subtitle">Implement the classic stencil example from https://open.gl/depthstencils</string> |
| 164 | 166 |
<string name="example_glow">Glowing Leaf</string> |
Also available in: Unified diff
New app checking Order Independent Transparency.