Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/wind/WindRenderer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.wind; |
21 | 21 |
|
22 |
import android.app.ActivityManager; |
|
23 |
import android.content.Context; |
|
24 |
import android.content.pm.ConfigurationInfo; |
|
25 |
import android.content.res.Resources; |
|
22 | 26 |
import android.graphics.Bitmap; |
23 | 27 |
import android.graphics.BitmapFactory; |
24 | 28 |
import android.opengl.GLSurfaceView; |
... | ... | |
46 | 50 |
|
47 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
48 | 52 |
|
49 |
class WindRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
53 |
class WindRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
50 | 54 |
{ |
51 | 55 |
private static final int X = 50; |
52 | 56 |
private static final int Y = 30; |
53 | 57 |
private static final int Z = 1; |
54 | 58 |
|
55 |
private GLSurfaceView mView; |
|
56 |
private DistortedTexture mTexture; |
|
57 |
private DistortedScreen mScreen; |
|
58 |
private WindEffectsManager mManager; |
|
59 |
private WindGust mGust; |
|
60 |
private Static3D mMove, mScale; |
|
61 |
private float mObjWidth, mObjHeight; |
|
59 |
private final GLSurfaceView mView; |
|
60 |
private final Resources mResources; |
|
61 |
private final DistortedTexture mTexture; |
|
62 |
private final DistortedScreen mScreen; |
|
63 |
private final WindEffectsManager mManager; |
|
64 |
private final WindGust mGust; |
|
65 |
private final Static3D mMove, mScale; |
|
66 |
private final float mObjWidth, mObjHeight; |
|
62 | 67 |
|
63 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 69 |
|
65 | 70 |
WindRenderer(GLSurfaceView view) |
66 | 71 |
{ |
67 | 72 |
mView = view; |
73 |
mResources = view.getResources(); |
|
68 | 74 |
|
69 | 75 |
MeshCubes cubes = new MeshCubes(X,Y,Z); |
70 | 76 |
DistortedEffects effects = new DistortedEffects(); |
... | ... | |
133 | 139 |
|
134 | 140 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
135 | 141 |
{ |
136 |
int min = width<height? width:height;
|
|
142 |
int min = Math.min(width,height);
|
|
137 | 143 |
|
138 | 144 |
float factor = ((float)min)/(mObjHeight + 1.4f*mObjWidth); |
139 | 145 |
mMove.set( factor*mObjHeight*1.28f -min*0.5f, min*0.5f - factor*mObjHeight*0.58f, 0 ); |
... | ... | |
158 | 164 |
{ |
159 | 165 |
is.close(); |
160 | 166 |
} |
161 |
catch(IOException e) { }
|
|
167 |
catch(IOException ignored) { }
|
|
162 | 168 |
} |
163 | 169 |
|
164 | 170 |
mTexture.setTexture(bitmap); |
... | ... | |
166 | 172 |
VertexEffectScale.enable(); |
167 | 173 |
VertexEffectDeform.enable(); |
168 | 174 |
VertexEffectWave.enable(); |
169 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
|
|
175 |
DistortedLibrary.onSurfaceCreated(this); |
|
170 | 176 |
} |
171 | 177 |
|
172 | 178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
175 | 181 |
{ |
176 | 182 |
android.util.Log.e("Wind", ex.getMessage() ); |
177 | 183 |
} |
184 |
|
|
185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
186 |
|
|
187 |
public int openGlVersion() |
|
188 |
{ |
|
189 |
Context context = mView.getContext(); |
|
190 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
191 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
192 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
193 |
int major = glESversion >> 16; |
|
194 |
int minor = glESversion & 0xff; |
|
195 |
|
|
196 |
return 100*major + 10*minor; |
|
197 |
} |
|
198 |
|
|
199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
200 |
|
|
201 |
public InputStream localFile(int fileID) |
|
202 |
{ |
|
203 |
return mResources.openRawResource(fileID); |
|
204 |
} |
|
205 |
|
|
206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
207 |
|
|
208 |
public void logMessage(String message) |
|
209 |
{ |
|
210 |
android.util.Log.e("Wind", message ); |
|
211 |
} |
|
178 | 212 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.