Revision 51554e47
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/examples/blur/BlurRenderer.java | ||
---|---|---|
91 | 91 |
|
92 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
93 | 93 |
|
94 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
95 |
{ |
|
96 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
97 |
|
|
98 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
99 |
{ |
|
100 |
int w = (height*bmpWidth)/bmpHeight; |
|
101 |
float factor = (float)height/bmpHeight; |
|
102 |
|
|
103 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
104 |
mEffects.scale(factor); |
|
105 |
} |
|
106 |
else |
|
107 |
{ |
|
108 |
int h = (width*bmpHeight)/bmpWidth; |
|
109 |
float factor = (float)width/bmpWidth; |
|
110 |
|
|
111 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
112 |
mEffects.scale(factor); |
|
113 |
} |
|
94 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
95 |
{ |
|
96 |
float qx = (float)width /bmpWidth; |
|
97 |
float qy = (float)height/bmpHeight; |
|
98 |
|
|
99 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
100 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
114 | 101 |
|
115 |
mScreen.resize(width, height);
|
|
116 |
}
|
|
102 |
mScreen.resize(width, height); |
|
103 |
} |
|
117 | 104 |
|
118 | 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
119 | 106 |
|
120 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
121 |
{
|
|
122 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
|
|
123 |
Bitmap bitmap;
|
|
107 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
108 |
{ |
|
109 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog); |
|
110 |
Bitmap bitmap; |
|
124 | 111 |
|
125 |
try
|
|
126 |
{
|
|
127 |
bitmap = BitmapFactory.decodeStream(is);
|
|
128 |
}
|
|
129 |
finally
|
|
130 |
{
|
|
131 |
try
|
|
132 |
{
|
|
133 |
is.close();
|
|
134 |
}
|
|
135 |
catch(IOException e) { }
|
|
136 |
}
|
|
112 |
try
|
|
113 |
{ |
|
114 |
bitmap = BitmapFactory.decodeStream(is); |
|
115 |
}
|
|
116 |
finally
|
|
117 |
{ |
|
118 |
try
|
|
119 |
{ |
|
120 |
is.close(); |
|
121 |
}
|
|
122 |
catch(IOException e) { } |
|
123 |
}
|
|
137 | 124 |
|
138 |
bmpHeight = bitmap.getHeight();
|
|
139 |
bmpWidth = bitmap.getWidth();
|
|
140 |
|
|
141 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
|
|
142 |
mTexture.setTexture(bitmap);
|
|
143 |
|
|
144 |
mScreen.detachAll();
|
|
145 |
DistortedNode node = new DistortedNode(mTexture,mEffects,mMesh);
|
|
146 |
node.setPostprocessEffects(mPostEffects);
|
|
147 |
mScreen.attach(node);
|
|
148 |
|
|
149 |
DistortedEffects.enableEffect(EffectNames.BLUR);
|
|
150 |
|
|
151 |
try
|
|
152 |
{
|
|
153 |
Distorted.onCreate(mView.getContext());
|
|
154 |
}
|
|
155 |
catch(Exception ex)
|
|
156 |
{
|
|
157 |
android.util.Log.e("Blur", ex.getMessage() );
|
|
158 |
}
|
|
159 |
}
|
|
125 |
bmpHeight = bitmap.getHeight(); |
|
126 |
bmpWidth = bitmap.getWidth(); |
|
127 |
|
|
128 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight); |
|
129 |
mTexture.setTexture(bitmap); |
|
130 |
|
|
131 |
mScreen.detachAll(); |
|
132 |
DistortedNode node = new DistortedNode(mTexture,mEffects,mMesh); |
|
133 |
node.setPostprocessEffects(mPostEffects); |
|
134 |
mScreen.attach(node); |
|
135 |
|
|
136 |
DistortedEffects.enableEffect(EffectNames.BLUR); |
|
137 |
|
|
138 |
try |
|
139 |
{ |
|
140 |
Distorted.onCreate(mView.getContext()); |
|
141 |
} |
|
142 |
catch(Exception ex) |
|
143 |
{ |
|
144 |
android.util.Log.e("Blur", ex.getMessage() ); |
|
145 |
} |
|
146 |
} |
|
160 | 147 |
} |
Also available in: Unified diff
Convert a few more APPs to the new resolution-independent Matrix Effects.