Revision 722c6ed3
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/examples/olimpic/OlimpicActivity.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.examples.olimpic; |
| 21 | 21 |
|
| 22 |
import org.distorted.examples.R; |
|
| 22 | 23 |
import org.distorted.library.Distorted; |
| 23 | 24 |
|
| 24 | 25 |
import android.app.Activity; |
| 26 |
import android.opengl.GLSurfaceView; |
|
| 25 | 27 |
import android.os.Bundle; |
| 28 |
import android.widget.TextView; |
|
| 26 | 29 |
|
| 27 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 31 |
|
| 29 | 32 |
public class OlimpicActivity extends Activity |
| 30 | 33 |
{
|
| 31 |
private OlimpicSurfaceView mView;
|
|
| 34 |
private TextView mText;
|
|
| 32 | 35 |
|
| 33 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 |
|
|
| 37 |
|
|
| 38 |
void setText(String text) |
|
| 39 |
{
|
|
| 40 |
mText.setText(text); |
|
| 41 |
} |
|
| 42 |
|
|
| 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 44 |
|
|
| 35 | 45 |
@Override |
| 36 | 46 |
protected void onCreate(Bundle icicle) |
| 37 | 47 |
{
|
| 38 | 48 |
super.onCreate(icicle); |
| 39 |
mView = new OlimpicSurfaceView(this);
|
|
| 40 |
setContentView(mView);
|
|
| 49 |
setContentView(R.layout.olimpiclayout);
|
|
| 50 |
mText = (TextView)findViewById(R.id.olimpicText);
|
|
| 41 | 51 |
} |
| 42 | 52 |
|
| 43 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 45 | 55 |
@Override |
| 46 | 56 |
protected void onPause() |
| 47 | 57 |
{
|
| 48 |
mView.onPause(); |
|
| 58 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.olimpicSurfaceView); |
|
| 59 |
view.onPause(); |
|
| 49 | 60 |
super.onPause(); |
| 50 | 61 |
} |
| 51 | 62 |
|
| ... | ... | |
| 55 | 66 |
protected void onResume() |
| 56 | 67 |
{
|
| 57 | 68 |
super.onResume(); |
| 58 |
mView.onResume(); |
|
| 69 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.olimpicSurfaceView); |
|
| 70 |
view.onResume(); |
|
| 59 | 71 |
} |
| 60 | 72 |
|
| 61 | 73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/examples/olimpic/OlimpicRenderer.java | ||
|---|---|---|
| 38 | 38 |
import org.distorted.library.Distorted; |
| 39 | 39 |
import org.distorted.library.DistortedTexture; |
| 40 | 40 |
|
| 41 |
import android.content.Context; |
|
| 41 | 42 |
import android.graphics.Bitmap; |
| 42 | 43 |
import android.graphics.BitmapFactory; |
| 43 | 44 |
import android.opengl.GLES30; |
| ... | ... | |
| 130 | 131 |
if( mCurrRendered!=mPrevRendered ) |
| 131 | 132 |
{
|
| 132 | 133 |
mPrevRendered = mCurrRendered; |
| 133 |
android.util.Log.d("Olympic", "rendered: "+mCurrRendered+" objects");
|
|
| 134 |
|
|
| 135 |
final OlimpicActivity act = (OlimpicActivity)mView.getContext(); |
|
| 136 |
|
|
| 137 |
act.runOnUiThread(new Runnable() |
|
| 138 |
{
|
|
| 139 |
public void run() |
|
| 140 |
{
|
|
| 141 |
act.setText("rendered: "+mCurrRendered+" objects");
|
|
| 142 |
} |
|
| 143 |
}); |
|
| 134 | 144 |
} |
| 135 | 145 |
} |
| 136 | 146 |
|
| src/main/java/org/distorted/examples/olimpic/OlimpicSurfaceView.java | ||
|---|---|---|
| 23 | 23 |
import android.content.Context; |
| 24 | 24 |
import android.content.pm.ConfigurationInfo; |
| 25 | 25 |
import android.opengl.GLSurfaceView; |
| 26 |
import android.util.AttributeSet; |
|
| 26 | 27 |
|
| 27 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 29 |
|
| ... | ... | |
| 30 | 31 |
{
|
| 31 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | 33 |
|
| 33 |
public OlimpicSurfaceView(Context context)
|
|
| 34 |
public OlimpicSurfaceView(Context context, AttributeSet attrs)
|
|
| 34 | 35 |
{
|
| 35 |
super(context); |
|
| 36 |
final ActivityManager activityManager = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 37 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 38 |
android.util.Log.e("View", "Using OpenGL ES "+configurationInfo.getGlEsVersion());
|
|
| 39 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
| 40 |
setRenderer(new OlimpicRenderer(this)); |
|
| 36 |
super(context,attrs); |
|
| 37 |
|
|
| 38 |
if(!isInEditMode()) |
|
| 39 |
{
|
|
| 40 |
final ActivityManager activityManager = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 41 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 42 |
android.util.Log.e("View", "Using OpenGL ES "+configurationInfo.getGlEsVersion());
|
|
| 43 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
| 44 |
setRenderer(new OlimpicRenderer(this)); |
|
| 45 |
} |
|
| 41 | 46 |
} |
| 42 | 47 |
} |
| 43 | 48 |
|
| src/main/res/layout/olimpiclayout.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:layout_width="fill_parent" |
|
| 4 |
android:layout_height="fill_parent" |
|
| 5 |
android:orientation="vertical" > |
|
| 6 |
|
|
| 7 |
<org.distorted.examples.olimpic.OlimpicSurfaceView |
|
| 8 |
android:id="@+id/olimpicSurfaceView" |
|
| 9 |
android:layout_width="fill_parent" |
|
| 10 |
android:layout_height="0dp" |
|
| 11 |
android:layout_weight="1" /> |
|
| 12 |
|
|
| 13 |
<LinearLayout |
|
| 14 |
android:id="@+id/linearLayout1" |
|
| 15 |
android:layout_width="fill_parent" |
|
| 16 |
android:layout_height="wrap_content" |
|
| 17 |
android:gravity="center|fill_horizontal" |
|
| 18 |
android:orientation="vertical" > |
|
| 19 |
|
|
| 20 |
<TextView |
|
| 21 |
android:id="@+id/olimpicText" |
|
| 22 |
android:layout_width="fill_parent" |
|
| 23 |
android:layout_height="0dp" |
|
| 24 |
android:layout_weight="0.5" |
|
| 25 |
android:gravity="center_vertical|center" |
|
| 26 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
| 27 |
|
|
| 28 |
</LinearLayout> |
|
| 29 |
|
|
| 30 |
</LinearLayout> |
|
Also available in: Unified diff
Improve Olimpic.