Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/predeform/PredeformRenderer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.predeform; |
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.opengl.GLSurfaceView; |
23 | 27 |
|
24 | 28 |
import org.distorted.library.effect.EffectType; |
... | ... | |
36 | 40 |
import org.distorted.library.type.Static3D; |
37 | 41 |
import org.distorted.library.type.Static4D; |
38 | 42 |
|
43 |
import java.io.InputStream; |
|
39 | 44 |
import java.util.ArrayList; |
40 | 45 |
|
41 | 46 |
import javax.microedition.khronos.egl.EGLConfig; |
... | ... | |
43 | 48 |
|
44 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 | 50 |
|
46 |
class PredeformRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
51 |
class PredeformRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
47 | 52 |
{ |
48 | 53 |
private static final float FOV = 30.0f; |
49 | 54 |
private static final float NEAR = 0.1f; |
50 | 55 |
|
51 | 56 |
private final GLSurfaceView mView; |
57 |
private final Resources mResources; |
|
52 | 58 |
private final DistortedTexture mTexture; |
53 | 59 |
private final DistortedEffects mEffects1, mEffects2; |
54 | 60 |
private final MeshBase mMesh1, mMesh2; |
... | ... | |
63 | 69 |
PredeformRenderer(GLSurfaceView v) |
64 | 70 |
{ |
65 | 71 |
mView = v; |
72 |
mResources = v.getResources(); |
|
66 | 73 |
|
67 | 74 |
mScale= new Static3D(1,1,1); |
68 | 75 |
mMove1= new Static3D(0,0,0); |
... | ... | |
133 | 140 |
{ |
134 | 141 |
float factor = SCALE*(Math.min(width, 0.5f*height)); |
135 | 142 |
mScale.set(factor,factor,factor); |
136 |
mMove1.set(0,+height*0.25f,0);
|
|
143 |
mMove1.set(0, height*0.25f,0);
|
|
137 | 144 |
mMove2.set(0,-height*0.25f,0); |
138 | 145 |
} |
139 | 146 |
else |
140 | 147 |
{ |
141 | 148 |
float factor = SCALE*(Math.min( 0.5f*width, height)); |
142 | 149 |
mScale.set(factor,factor,factor); |
143 |
mMove1.set(+width*0.25f,0,0);
|
|
150 |
mMove1.set( width*0.25f,0,0);
|
|
144 | 151 |
mMove2.set(-width*0.25f,0,0); |
145 | 152 |
} |
146 | 153 |
|
... | ... | |
181 | 188 |
Effect.enableEffects(EffectType.VERTEX); |
182 | 189 |
|
183 | 190 |
DistortedLibrary.needTransformFeedback(); |
184 |
DistortedLibrary.onSurfaceCreated(act, this);
|
|
191 |
DistortedLibrary.onSurfaceCreated(this); |
|
185 | 192 |
} |
186 | 193 |
|
187 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
190 | 197 |
{ |
191 | 198 |
android.util.Log.e("Predeform", ex.getMessage() ); |
192 | 199 |
} |
200 |
|
|
201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
202 |
|
|
203 |
public int openGlVersion() |
|
204 |
{ |
|
205 |
Context context = mView.getContext(); |
|
206 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
207 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
208 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
209 |
int major = glESversion >> 16; |
|
210 |
int minor = glESversion & 0xff; |
|
211 |
|
|
212 |
return 100*major + 10*minor; |
|
213 |
} |
|
214 |
|
|
215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
216 |
|
|
217 |
public InputStream localFile(int fileID) |
|
218 |
{ |
|
219 |
return mResources.openRawResource(fileID); |
|
220 |
} |
|
221 |
|
|
222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
223 |
|
|
224 |
public void logMessage(String message) |
|
225 |
{ |
|
226 |
android.util.Log.e("Predeform", message ); |
|
227 |
} |
|
193 | 228 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.