27 |
27 |
|
28 |
28 |
import org.distorted.examples.R;
|
29 |
29 |
|
|
30 |
import org.distorted.library.effect.EffectName;
|
|
31 |
import org.distorted.library.effect.FragmentEffectChroma;
|
|
32 |
import org.distorted.library.effect.MatrixEffectMove;
|
|
33 |
import org.distorted.library.effect.MatrixEffectScale;
|
|
34 |
import org.distorted.library.effect.VertexEffectDeform;
|
|
35 |
import org.distorted.library.effect.VertexEffectSwirl;
|
30 |
36 |
import org.distorted.library.main.Distorted;
|
31 |
37 |
import org.distorted.library.main.DistortedEffects;
|
32 |
38 |
import org.distorted.library.main.DistortedScreen;
|
33 |
39 |
import org.distorted.library.main.DistortedTexture;
|
34 |
|
import org.distorted.library.EffectNames;
|
35 |
40 |
import org.distorted.library.main.MeshFlat;
|
36 |
|
import org.distorted.library.EffectTypes;
|
37 |
41 |
import org.distorted.library.type.Dynamic3D;
|
38 |
42 |
import org.distorted.library.type.Static1D;
|
39 |
43 |
import org.distorted.library.type.Static3D;
|
... | ... | |
61 |
65 |
private DistortedTexture mTexture;
|
62 |
66 |
private MeshFlat mMesh;
|
63 |
67 |
private DistortedScreen mScreen;
|
64 |
|
private int bmpHeight, bmpWidth;
|
|
68 |
private int mObjHeight, mObjWidth;
|
|
69 |
private Static3D mMove, mScale;
|
|
70 |
private Static3D mSwirl1, mSwirl2, mDeform1, mDeform2;
|
65 |
71 |
|
66 |
72 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
73 |
|
68 |
74 |
CheckRenderer(GLSurfaceView view)
|
69 |
75 |
{
|
70 |
76 |
mView = view;
|
71 |
|
mEffects = new DistortedEffects();
|
72 |
77 |
|
73 |
78 |
CheckActivity act = (CheckActivity)mView.getContext();
|
74 |
79 |
|
75 |
80 |
DistortedEffects.setMaxVertex(act.getMaxV());
|
76 |
81 |
DistortedEffects.setMaxFragment(act.getMaxF());
|
|
82 |
DistortedEffects.enableEffect(EffectName.SWIRL);
|
|
83 |
DistortedEffects.enableEffect(EffectName.DEFORM);
|
|
84 |
DistortedEffects.enableEffect(EffectName.CHROMA);
|
|
85 |
|
|
86 |
mSwirl1 = new Static3D(0,0,0);
|
|
87 |
mSwirl2 = new Static3D(0,0,0);
|
|
88 |
mDeform1= new Static3D(0,0,0);
|
|
89 |
mDeform2= new Static3D(0,0,0);
|
|
90 |
|
|
91 |
mMove = new Static3D(0,0,0);
|
|
92 |
mScale= new Static3D(1,1,1);
|
|
93 |
mEffects = new DistortedEffects();
|
|
94 |
mEffects.apply(new MatrixEffectMove(mMove));
|
|
95 |
mEffects.apply(new MatrixEffectScale(mScale));
|
|
96 |
|
|
97 |
// Try adding 2 Vertex Effects to the Bitmap.
|
|
98 |
// This will fail if we have set maxVertexEffects to something < 2.
|
|
99 |
//
|
|
100 |
// Even if adding some of the Effects fails, the App will still start - you just won't see
|
|
101 |
// the effects that failed to add.
|
|
102 |
|
|
103 |
Dynamic3D dSwirl = new Dynamic3D(2000,0.0f);
|
|
104 |
dSwirl.add(mSwirl1);
|
|
105 |
dSwirl.add(mSwirl2);
|
|
106 |
|
|
107 |
if( !mEffects.apply( new VertexEffectSwirl(new Static1D(30), dSwirl, new Static4D( 0,0,40,40)) ) )
|
|
108 |
{
|
|
109 |
Log.e("Check", "Failed to add Swirl effect!");
|
|
110 |
}
|
|
111 |
|
|
112 |
Dynamic3D dDeform = new Dynamic3D(2000,0.0f);
|
|
113 |
dDeform.add(mDeform1);
|
|
114 |
dDeform.add(mDeform2);
|
|
115 |
|
|
116 |
if( !mEffects.apply( new VertexEffectDeform(dDeform, new Static3D(mObjWidth/2,0,0)) ) )
|
|
117 |
{
|
|
118 |
Log.e("Check", "Failed to add Deform effect!");
|
|
119 |
}
|
|
120 |
|
|
121 |
// Now try adding 1 Fragment Effect. Likewise, will fail if maxFragmentEffects is <1.
|
|
122 |
Static3D color = new Static3D(1,0,0);
|
|
123 |
Dynamic1D inter = new Dynamic1D(2000,0.0f);
|
|
124 |
inter.add(new Static1D(0));
|
|
125 |
inter.add(new Static1D(1));
|
|
126 |
|
|
127 |
if( !mEffects.apply( new FragmentEffectChroma(inter, color) ) )
|
|
128 |
{
|
|
129 |
Log.e("Check", "Failed to add Chroma effect!");
|
|
130 |
}
|
77 |
131 |
|
78 |
132 |
mScreen = new DistortedScreen(mView);
|
79 |
133 |
}
|
... | ... | |
89 |
143 |
|
90 |
144 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
91 |
145 |
{
|
92 |
|
mEffects.abortEffects(EffectTypes.MATRIX);
|
93 |
|
|
94 |
|
if( (float)bmpHeight/bmpWidth > (float)height/width )
|
|
146 |
if( (float)mObjHeight/mObjWidth > (float)height/width )
|
95 |
147 |
{
|
96 |
|
int w = (height*bmpWidth)/bmpHeight;
|
97 |
|
float factor = (float)height/bmpHeight;
|
98 |
|
|
99 |
|
mEffects.move( new Static3D((width-w)/2,0,0) );
|
100 |
|
mEffects.scale(factor);
|
|
148 |
int w = (height*mObjWidth)/mObjHeight;
|
|
149 |
float factor = (float)height/mObjHeight;
|
|
150 |
mMove.set((width-w)/2,0,0);
|
|
151 |
mScale.set(factor,factor,factor);
|
101 |
152 |
}
|
102 |
153 |
else
|
103 |
154 |
{
|
104 |
|
int h = (width*bmpHeight)/bmpWidth;
|
105 |
|
float factor = (float)width/bmpWidth;
|
106 |
|
|
107 |
|
mEffects.move( new Static3D(0,(height-h)/2,0) );
|
108 |
|
mEffects.scale(factor);
|
|
155 |
int h = (width*mObjHeight)/mObjWidth;
|
|
156 |
float factor = (float)width/mObjWidth;
|
|
157 |
mMove.set(0,(height-h)/2,0);
|
|
158 |
mScale.set(factor,factor,factor);
|
109 |
159 |
}
|
110 |
|
|
111 |
|
mScreen.resize(width, height);
|
|
160 |
|
|
161 |
mScreen.resize(width,height);
|
112 |
162 |
}
|
113 |
163 |
|
114 |
164 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
131 |
181 |
catch(IOException e) { }
|
132 |
182 |
}
|
133 |
183 |
|
134 |
|
bmpHeight = bitmap.getHeight();
|
135 |
|
bmpWidth = bitmap.getWidth();
|
|
184 |
mObjHeight = bitmap.getHeight();
|
|
185 |
mObjWidth = bitmap.getWidth();
|
136 |
186 |
|
137 |
|
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
|
|
187 |
if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
|
138 |
188 |
mTexture.setTexture(bitmap);
|
139 |
189 |
|
140 |
|
if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
|
|
190 |
if( mMesh==null ) mMesh = new MeshFlat(30,30*mObjHeight/mObjWidth);
|
141 |
191 |
|
142 |
192 |
mScreen.detachAll();
|
143 |
193 |
mScreen.attach(mTexture,mEffects,mMesh);
|
144 |
194 |
|
145 |
|
mEffects.abortEffects(EffectTypes.VERTEX);
|
146 |
|
mEffects.abortEffects(EffectTypes.FRAGMENT);
|
147 |
|
|
148 |
|
// Try adding 2 Vertex Effects to the Bitmap.
|
149 |
|
// This will fail if we have set maxVertexEffects to something < 2.
|
150 |
|
//
|
151 |
|
// Even if adding some of the Effects fails, the App will still start - you just won't see
|
152 |
|
// the effects that failed to add.
|
153 |
|
|
154 |
|
Dynamic3D dSwirl = new Dynamic3D(2000,0.0f);
|
155 |
|
dSwirl.add(new Static3D( 0, bmpHeight/2, 0));
|
156 |
|
dSwirl.add(new Static3D( bmpWidth, bmpHeight/2, 0));
|
157 |
|
|
158 |
|
long swirlEffectID = mEffects.swirl( new Static1D(30), dSwirl, new Static4D( 0,0,40,40) );
|
159 |
|
|
160 |
|
if( swirlEffectID<0 )
|
161 |
|
{
|
162 |
|
Log.e("Check", "Failed to add Swirl effect!");
|
163 |
|
}
|
164 |
|
|
165 |
|
Dynamic3D dDeform = new Dynamic3D(2000,0.0f);
|
166 |
|
dDeform.add(new Static3D( 0, 0,0));
|
167 |
|
dDeform.add(new Static3D( 0,-bmpHeight,0));
|
168 |
|
|
169 |
|
long deformEffectID = mEffects.deform(dDeform, new Static3D(bmpWidth/2,0,0) );
|
170 |
|
|
171 |
|
if( deformEffectID<0 )
|
172 |
|
{
|
173 |
|
Log.e("Check", "Failed to add Deform effect!");
|
174 |
|
}
|
175 |
|
|
176 |
|
// Now try adding 1 Fragment Effect. Likewise, will fail if maxFragmentEffects is <1.
|
177 |
|
Static3D color = new Static3D(1,0,0);
|
178 |
|
Dynamic1D inter = new Dynamic1D(2000,0.0f);
|
179 |
|
inter.add(new Static1D(0));
|
180 |
|
inter.add(new Static1D(1));
|
181 |
|
|
182 |
|
long chromaEffectID = mEffects.chroma(inter, color);
|
183 |
|
|
184 |
|
if( chromaEffectID<0 )
|
185 |
|
{
|
186 |
|
Log.e("Check", "Failed to add Chroma effect!");
|
187 |
|
}
|
188 |
|
|
189 |
|
DistortedEffects.enableEffect(EffectNames.SWIRL);
|
190 |
|
DistortedEffects.enableEffect(EffectNames.DEFORM);
|
191 |
|
DistortedEffects.enableEffect(EffectNames.CHROMA);
|
|
195 |
mSwirl1.set ( 0, mObjHeight/2, 0);
|
|
196 |
mSwirl2.set (mObjWidth, mObjHeight/2, 0);
|
|
197 |
mDeform1.set( 0, 0 , 0);
|
|
198 |
mDeform2.set( 0,-mObjHeight , 0);
|
192 |
199 |
|
193 |
200 |
try
|
194 |
201 |
{
|
Further progress with Apps.