Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java | ||
---|---|---|
37 | 37 |
import org.distorted.library.type.Static3D; |
38 | 38 |
import org.distorted.library.type.Static4D; |
39 | 39 |
|
40 |
import android.app.ActivityManager; |
|
41 |
import android.content.Context; |
|
42 |
import android.content.pm.ConfigurationInfo; |
|
43 |
import android.content.res.Resources; |
|
40 | 44 |
import android.graphics.Bitmap; |
41 | 45 |
import android.graphics.BitmapFactory; |
42 | 46 |
import android.opengl.GLSurfaceView; |
43 | 47 |
|
44 | 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 | 49 |
|
46 |
class MonaLisaRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
50 |
class MonaLisaRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
47 | 51 |
{ |
48 |
private GLSurfaceView mView; |
|
49 |
private DistortedEffects mEffects; |
|
50 |
private DistortedTexture mTexture; |
|
52 |
private final GLSurfaceView mView; |
|
53 |
private final Resources mResources; |
|
54 |
private final DistortedEffects mEffects; |
|
55 |
private final DistortedTexture mTexture; |
|
56 |
private final DistortedScreen mScreen; |
|
57 |
private final Static3D mScale; |
|
58 |
|
|
51 | 59 |
private MeshSquare mMesh; |
52 |
private DistortedScreen mScreen; |
|
53 |
private Static3D mScale; |
|
54 | 60 |
private float mBmpRatio; |
55 | 61 |
|
56 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
58 | 64 |
MonaLisaRenderer(GLSurfaceView v) |
59 | 65 |
{ |
60 | 66 |
mView = v; |
67 |
mResources = v.getResources(); |
|
61 | 68 |
|
62 | 69 |
// Centers of the Effects. |
63 | 70 |
// center = (0,0,0) would be the midpoint of the Bitmap. |
... | ... | |
137 | 144 |
{ |
138 | 145 |
is.close(); |
139 | 146 |
} |
140 |
catch(IOException e) { }
|
|
147 |
catch(IOException ignored) { }
|
|
141 | 148 |
} |
142 | 149 |
|
143 | 150 |
mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth(); |
... | ... | |
161 | 168 |
// before the call to DistortedLibrary.onCreate(). Best done here. |
162 | 169 |
VertexEffectDistort.enable(); |
163 | 170 |
|
164 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
|
|
171 |
DistortedLibrary.onSurfaceCreated(this); |
|
165 | 172 |
} |
166 | 173 |
|
167 | 174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
170 | 177 |
{ |
171 | 178 |
android.util.Log.e("MonaLisa", ex.getMessage() ); |
172 | 179 |
} |
180 |
|
|
181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
182 |
|
|
183 |
public int openGlVersion() |
|
184 |
{ |
|
185 |
Context context = mView.getContext(); |
|
186 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
187 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
188 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
189 |
int major = glESversion >> 16; |
|
190 |
int minor = glESversion & 0xff; |
|
191 |
|
|
192 |
return 100*major + 10*minor; |
|
193 |
} |
|
194 |
|
|
195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
196 |
|
|
197 |
public InputStream localFile(int fileID) |
|
198 |
{ |
|
199 |
return mResources.openRawResource(fileID); |
|
200 |
} |
|
201 |
|
|
202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
203 |
|
|
204 |
public void logMessage(String message) |
|
205 |
{ |
|
206 |
android.util.Log.e("MonaLisa", message ); |
|
207 |
} |
|
173 | 208 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.