Revision d0ad3964
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/tutorials/TutorialRenderer.java | ||
---|---|---|
12 | 12 |
import javax.microedition.khronos.egl.EGLConfig; |
13 | 13 |
import javax.microedition.khronos.opengles.GL10; |
14 | 14 |
|
15 |
import android.app.ActivityManager; |
|
16 |
import android.content.Context; |
|
17 |
import android.content.pm.ConfigurationInfo; |
|
18 |
import android.content.res.Resources; |
|
15 | 19 |
import android.opengl.GLSurfaceView; |
16 | 20 |
|
17 | 21 |
import org.distorted.library.effect.EffectType; |
... | ... | |
24 | 28 |
import org.distorted.objectlib.effects.BaseEffect; |
25 | 29 |
import org.distorted.objectlib.main.ObjectControl; |
26 | 30 |
|
31 |
import java.io.InputStream; |
|
32 |
|
|
27 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
28 | 34 |
|
29 |
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
35 |
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
30 | 36 |
{ |
31 | 37 |
private final TutorialSurfaceView mView; |
32 | 38 |
private final DistortedScreen mScreen; |
39 |
private final Resources mResources; |
|
33 | 40 |
|
34 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
35 | 42 |
|
... | ... | |
38 | 45 |
final float BRIGHTNESS = 0.30f; |
39 | 46 |
|
40 | 47 |
mView = v; |
48 |
mResources = v.getResources(); |
|
41 | 49 |
mScreen = new DistortedScreen(); |
42 | 50 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
43 | 51 |
} |
44 | 52 |
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
DistortedScreen getScreen() |
|
56 |
{ |
|
57 |
return mScreen; |
|
58 |
} |
|
59 |
|
|
45 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 61 |
|
47 | 62 |
@Override |
... | ... | |
73 | 88 |
VertexEffectQuaternion.enable(); |
74 | 89 |
BaseEffect.Type.enableEffects(); |
75 | 90 |
|
76 |
DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
|
|
91 |
DistortedLibrary.onSurfaceCreated(this,1); |
|
77 | 92 |
DistortedLibrary.setCull(true); |
78 | 93 |
} |
79 | 94 |
|
... | ... | |
81 | 96 |
|
82 | 97 |
public void distortedException(Exception ex) |
83 | 98 |
{ |
84 |
android.util.Log.e("TUTORIAL", "unexpected exception: "+ex.getMessage() );
|
|
99 |
android.util.Log.e("Tutorial", "unexpected exception: "+ex.getMessage() );
|
|
85 | 100 |
} |
86 | 101 |
|
87 | 102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
88 | 103 |
|
89 |
DistortedScreen getScreen()
|
|
104 |
public int openGlVersion()
|
|
90 | 105 |
{ |
91 |
return mScreen; |
|
106 |
Context context = mView.getContext(); |
|
107 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
108 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
109 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
110 |
int major = glESversion >> 16; |
|
111 |
int minor = glESversion & 0xff; |
|
112 |
|
|
113 |
return 100*major + 10*minor; |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
public InputStream localFile(int fileID) |
|
119 |
{ |
|
120 |
return mResources.openRawResource(fileID); |
|
121 |
} |
|
122 |
|
|
123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 |
|
|
125 |
public void logMessage(String message) |
|
126 |
{ |
|
127 |
android.util.Log.e("Tutorial", message ); |
|
92 | 128 |
} |
93 | 129 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.