Revision e4330c89
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/examples/girl/GirlRenderer.java | ||
---|---|---|
129 | 129 |
mEffects.apply(new MatrixEffectMove(mMove)); |
130 | 130 |
mEffects.apply(new MatrixEffectScale(mScale)); |
131 | 131 |
|
132 |
mScreen = new DistortedScreen(mView);
|
|
132 |
mScreen = new DistortedScreen(); |
|
133 | 133 |
} |
134 | 134 |
|
135 | 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
166 | 166 |
|
167 | 167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
168 | 168 |
|
169 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
170 |
{
|
|
171 |
if( (float)bmpHeight/bmpWidth > (float)height/width )
|
|
172 |
{
|
|
173 |
int w = (height*bmpWidth)/bmpHeight;
|
|
174 |
float factor = (float)height/bmpHeight;
|
|
175 |
|
|
176 |
mMove.set((width-w)/2,0,0);
|
|
177 |
mScale.set(factor,factor,factor);
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
int h = (width*bmpHeight)/bmpWidth;
|
|
182 |
float factor = (float)width/bmpWidth;
|
|
183 |
|
|
184 |
mMove.set(0,(height-h)/2,0);
|
|
185 |
mScale.set(factor,factor,factor);
|
|
186 |
}
|
|
169 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
170 |
{
|
|
171 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
172 |
{ |
|
173 |
int w = (height*bmpWidth)/bmpHeight; |
|
174 |
float factor = (float)height/bmpHeight; |
|
175 |
|
|
176 |
mMove.set((width-w)/2,0,0); |
|
177 |
mScale.set(factor,factor,factor); |
|
178 |
} |
|
179 |
else |
|
180 |
{ |
|
181 |
int h = (width*bmpHeight)/bmpWidth; |
|
182 |
float factor = (float)width/bmpWidth; |
|
183 |
|
|
184 |
mMove.set(0,(height-h)/2,0); |
|
185 |
mScale.set(factor,factor,factor); |
|
186 |
} |
|
187 | 187 |
|
188 |
mScreen.resize(width, height);
|
|
189 |
}
|
|
188 |
mScreen.resize(width, height); |
|
189 |
} |
|
190 | 190 |
|
191 | 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
192 | 192 |
|
193 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
194 |
{
|
|
195 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
|
|
196 |
Bitmap bitmap;
|
|
193 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
194 |
{ |
|
195 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl); |
|
196 |
Bitmap bitmap; |
|
197 | 197 |
|
198 |
try
|
|
199 |
{
|
|
200 |
bitmap = BitmapFactory.decodeStream(is);
|
|
201 |
}
|
|
202 |
finally
|
|
203 |
{
|
|
204 |
try
|
|
205 |
{
|
|
206 |
is.close();
|
|
207 |
}
|
|
208 |
catch(IOException e) { }
|
|
209 |
}
|
|
198 |
try
|
|
199 |
{ |
|
200 |
bitmap = BitmapFactory.decodeStream(is); |
|
201 |
}
|
|
202 |
finally
|
|
203 |
{ |
|
204 |
try
|
|
205 |
{ |
|
206 |
is.close(); |
|
207 |
}
|
|
208 |
catch(IOException e) { } |
|
209 |
}
|
|
210 | 210 |
|
211 |
bmpHeight = bitmap.getHeight();
|
|
212 |
bmpWidth = bitmap.getWidth();
|
|
211 |
bmpHeight = bitmap.getHeight(); |
|
212 |
bmpWidth = bitmap.getWidth(); |
|
213 | 213 |
|
214 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
|
|
215 |
mTexture.setTexture(bitmap);
|
|
214 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight); |
|
215 |
mTexture.setTexture(bitmap); |
|
216 | 216 |
|
217 |
if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
|
|
217 |
if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth); |
|
218 | 218 |
|
219 |
mScreen.detachAll();
|
|
220 |
mScreen.attach(mTexture,mEffects,mMesh);
|
|
219 |
mScreen.detachAll(); |
|
220 |
mScreen.attach(mTexture,mEffects,mMesh); |
|
221 | 221 |
|
222 |
DistortedEffects.enableEffect(EffectName.DISTORT);
|
|
223 |
DistortedEffects.enableEffect(EffectName.SINK);
|
|
224 |
DistortedEffects.enableEffect(EffectName.SWIRL);
|
|
222 |
DistortedEffects.enableEffect(EffectName.DISTORT); |
|
223 |
DistortedEffects.enableEffect(EffectName.SINK); |
|
224 |
DistortedEffects.enableEffect(EffectName.SWIRL); |
|
225 | 225 |
|
226 |
try
|
|
227 |
{
|
|
228 |
Distorted.onCreate(mView.getContext());
|
|
229 |
}
|
|
230 |
catch(Exception ex)
|
|
231 |
{
|
|
232 |
android.util.Log.e("Renderer", ex.getMessage() );
|
|
233 |
}
|
|
234 |
}
|
|
226 |
try |
|
227 |
{ |
|
228 |
Distorted.onCreate(mView.getContext()); |
|
229 |
} |
|
230 |
catch(Exception ex) |
|
231 |
{ |
|
232 |
android.util.Log.e("Renderer", ex.getMessage() ); |
|
233 |
} |
|
234 |
} |
|
235 | 235 |
} |
Also available in: Unified diff
Change of API: move setting the EGL context back to the APP.