Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java | ||
---|---|---|
44 | 44 |
import org.distorted.library.main.DistortedTexture; |
45 | 45 |
import org.distorted.library.main.DistortedEffects; |
46 | 46 |
|
47 |
import android.app.ActivityManager; |
|
48 |
import android.content.Context; |
|
49 |
import android.content.pm.ConfigurationInfo; |
|
50 |
import android.content.res.Resources; |
|
47 | 51 |
import android.graphics.Bitmap; |
48 | 52 |
import android.graphics.BitmapFactory; |
49 | 53 |
import android.graphics.Canvas; |
... | ... | |
54 | 58 |
|
55 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 60 |
|
57 |
class StarWarsRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.ExceptionListener
|
|
61 |
class StarWarsRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.LibraryUser
|
|
58 | 62 |
{ |
59 | 63 |
private final String[] mGFFAString = |
60 | 64 |
|
... | ... | |
104 | 108 |
private final float CRAWL_ANGLE = -30.0f; |
105 | 109 |
private final float FOV_ANGLE = 60.0f; |
106 | 110 |
|
107 |
private GLSurfaceView mView; |
|
111 |
private final GLSurfaceView mView; |
|
112 |
private final DistortedEffects mGFFAEffects, mLogoEffects, mCrawlEffects, mCrawlBackgroundEffects; |
|
113 |
private final DistortedEffects[] mStarEffects; |
|
114 |
private final DistortedScreen mScreen; |
|
115 |
private final MeshQuad mQuad; |
|
116 |
private final Random mRnd = new Random(0); |
|
117 |
private final Resources mResources; |
|
118 |
|
|
108 | 119 |
private DistortedTexture mGFFATexture, mLogoTexture, mCrawlTexture, mCrawlBackgroundTexture, mStarTexture; |
109 |
private DistortedEffects mGFFAEffects, mLogoEffects, mCrawlEffects, mCrawlBackgroundEffects; |
|
110 |
private DistortedEffects[] mStarEffects; |
|
111 | 120 |
private DistortedNode mBackground; |
112 |
private DistortedScreen mScreen; |
|
113 |
private MeshQuad mQuad; |
|
114 |
|
|
115 | 121 |
private long alphaEffectID, scaleEffectID, moveEffectID; |
116 |
private Random mRnd = new Random(0); |
|
117 | 122 |
private int mWidth, mHeight; |
118 | 123 |
private float mLogoRatio; |
119 | 124 |
private int mCrawlBackgroundW, mCrawlBackgroundH; |
... | ... | |
123 | 128 |
StarWarsRenderer(GLSurfaceView v) |
124 | 129 |
{ |
125 | 130 |
mView = v; |
131 |
mResources = v.getResources(); |
|
126 | 132 |
|
127 | 133 |
mQuad = new MeshQuad(); |
128 | 134 |
|
... | ... | |
187 | 193 |
{ |
188 | 194 |
setupBitmaps(); |
189 | 195 |
FragmentEffectAlpha.enable(); |
190 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this); |
|
191 |
} |
|
192 |
|
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
|
|
195 |
public void distortedException(Exception ex) |
|
196 |
{ |
|
197 |
android.util.Log.e("StarWars", ex.getMessage() ); |
|
196 |
DistortedLibrary.onSurfaceCreated(this); |
|
198 | 197 |
} |
199 | 198 |
|
200 | 199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
434 | 433 |
mCrawlBackgroundTexture.markForDeletion(); |
435 | 434 |
} |
436 | 435 |
} |
436 |
|
|
437 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
438 |
|
|
439 |
public void distortedException(Exception ex) |
|
440 |
{ |
|
441 |
android.util.Log.e("StarWars", ex.getMessage() ); |
|
442 |
} |
|
443 |
|
|
444 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
445 |
|
|
446 |
public int openGlVersion() |
|
447 |
{ |
|
448 |
Context context = mView.getContext(); |
|
449 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
450 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
451 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
452 |
int major = glESversion >> 16; |
|
453 |
int minor = glESversion & 0xff; |
|
454 |
|
|
455 |
return 100*major + 10*minor; |
|
456 |
} |
|
457 |
|
|
458 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
459 |
|
|
460 |
public InputStream localFile(int fileID) |
|
461 |
{ |
|
462 |
return mResources.openRawResource(fileID); |
|
463 |
} |
|
464 |
|
|
465 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
466 |
|
|
467 |
public void logMessage(String message) |
|
468 |
{ |
|
469 |
android.util.Log.e("StarWars", message ); |
|
470 |
} |
|
437 | 471 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.