How to modify the Android OpenGL ES 1.0 tutorial to use XML and a framelayout -


the opengl es 1.0 tutorial listed here (http://developer.android.com/resources/tutorials/opengl/opengl-es10.html) works want make work multiple layers , xml framelayout. have this:

-class extends activity

-class b extends glsurfaceview

-class c implements glsurfaceview.renderer

the original example has class b handling touch events , class c rendering object displayed. want extend further adding additional geometry layers. have working camera layout (although crashes when changing orientation).

working version (main.java):

public class main extends activity {     mainsurfaceview mglview; cameraview cameraview;  /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      //set full screen     requestwindowfeature(window.feature_no_title);     getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);      mglview = new mainsurfaceview(this, null);     setcontentview(mglview);      cameraview = new cameraview(this, null);     addcontentview(cameraview, new layoutparams(layoutparams.match_parent, layoutparams.match_parent)); } 

non working want fix (main.java):

public class main extends activity {     mainsurfaceview mglview; cameraview cameraview;  /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      //set full screen     requestwindowfeature(window.feature_no_title);     getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);      setcontentview(r.layout.main);      mglview = (mainsurfaceview) findviewbyid(r.id.glsurfaceview)      cameraview = (cameraview) findviewbyid(r.id.camera); } 

the custom view class (mainsurfaceview.java(

public class mainsurfaceview extends glsurfaceview {  private final float touch_scale_factor = 180.0f / 320; private mainrenderer mrenderer; private float mpreviousx; private float mpreviousy;  public mainsurfaceview(context context, attributeset attrs) {     super(context, attrs);      mrenderer = new mainrenderer();     seteglconfigchooser(8, 8, 8, 8, 16, 0);       setrenderer(mrenderer);     getholder().setformat(pixelformat.translucent);      setzorderontop(true);      //render when there change     setrendermode(glsurfaceview.rendermode_when_dirty);  }     ... 

the non working code crashing due unhandled exception? why when handle eception in cameraview.java

...     try {         camera.setpreviewdisplay( holder );     } catch( ioexception e ) {         e.printstacktrace();     }     // ...and start previewing. on, camera keeps pushing preview     // images surface.     camera.startpreview(); 

the xml file (main.xml)

    <?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android"       android:layout_width="fill_parent"       android:layout_height="fill_parent" >        <android.opengl.glsurfaceview           android:id="@+id/glsurfaceview"           android:layout_width="match_parent"           android:layout_height="match_parent" />        <surfaceview           android:id="@+id/camera"           android:layout_width="match_parent"           android:layout_height="match_parent"           android:keepscreenon="true" /> </framelayout> 

full logcat trace around exception

06-05 12:34:40.386: d/androidruntime(282): shutting down vm 06-05 12:34:40.396: w/dalvikvm(282): threadid=1: thread exiting uncaught exception (group=0x4001d800)

06-05 12:34:40.466: e/androidruntime(282): fatal exception: main 06-05 12:34:40.466: e/androidruntime(282): java.lang.runtimeexception: unable start activity componentinfo{com.zypath.opengltest/com.zypath.opengltest.main}: java.lang.classcastexception: android.opengl.glsurfaceview

06-05 12:34:40.466: e/androidruntime(282): @ android.app.activitythread.performlaunchactivity(activitythread.java:2663)

06-05 12:34:40.466: e/androidruntime(282): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2679)

06-05 12:34:40.466: e/androidruntime(282): @ android.app.activitythread.access$2300(activitythread.java:125)

06-05 12:34:40.466: e/androidruntime(282): @ android.app.activitythread$h.handlemessage(activitythread.java:2033)

06-05 12:34:40.466: e/androidruntime(282): @ android.os.handler.dispatchmessage(handler.java:99)

06-05 12:34:40.466: e/androidruntime(282): @ android.os.looper.loop(looper.java:123) 06-05 12:34:40.466: e/androidruntime(282): @ android.app.activitythread.main(activitythread.java:4627)

06-05 12:34:40.466: e/androidruntime(282): @ java.lang.reflect.method.invokenative(native method)

06-05 12:34:40.466: e/androidruntime(282): @ java.lang.reflect.method.invoke(method.java:521)

06-05 12:34:40.466: e/androidruntime(282): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868)

06-05 12:34:40.466: e/androidruntime(282): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626)

06-05 12:34:40.466: e/androidruntime(282): @ dalvik.system.nativestart.main(native method)

06-05 12:34:40.466: e/androidruntime(282): caused by: java.lang.classcastexception: android.opengl.glsurfaceview

06-05 12:34:40.466: e/androidruntime(282): @ com.zypath.opengltest.main.oncreate(main.java:33)

06-05 12:34:40.466: e/androidruntime(282): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047)

06-05 12:34:40.466: e/androidruntime(282): @ android.app.activitythread.performlaunchactivity(activitythread.java:2627)

06-05 12:34:40.466: e/androidruntime(282): ... 11 more 06-05 12:34:42.806: i/process(282): sending signal. pid: 282 sig: 9

i have been through several examples , that's got mainsurfaceview constructor(context context, attributeset attrs) use xml views. doing wrong here??

fixed had forgot refer custom view class , camera class in xml file. correct xml file looks this:

<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android"       android:layout_width="fill_parent"       android:layout_height="fill_parent" >        <com.company.opengltest.mainsurfaceview           android:id="@+id/glsurfaceview"           android:layout_width="match_parent"           android:layout_height="match_parent" />        <com.company.opengltest.cameraview           android:id="@+id/camera"           android:layout_width="match_parent"           android:layout_height="match_parent"           android:keepscreenon="true" /> </framelayout> 


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -