opengl es - 2d Triangle on open-es on android emulator 8 -
hey trying draw triangle on opengl. followed tutorial it. eventhough seems fine not work. everytime run code sends me main menu.
after debugging noticed application stucks @ line
gl.gldrawelements(gl10.gl_triangles, pindex.length, gl10.gl_unsigned_short, pbuff);
this glexample.java class
public class glexample extends activity { glsurfaceview oursurface; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); oursurface = new glsurfaceview(this); oursurface.setrenderer(new glrendererex()); setcontentview(oursurface); } @override protected void onpause() { super.onpause(); oursurface.onpause(); } @override protected void onresume() { super.onresume(); oursurface.onresume(); } }
this gltriangleex class
public class gltriangleex { private float vertices[] = { 0f, 1f, // p0 1f, -1f, // p1 -1f, -1f // p2 }; private floatbuffer vertbuff; private short[] pindex = { 0, 1, 2 }; private shortbuffer pbuff; public gltriangleex() { // bir float için 4 byte gerektiğinden length * 4 oldu bytebuffer bbuff = bytebuffer.allocatedirect(vertices.length * 4); bbuff.order(byteorder.nativeorder()); vertbuff = bbuff.asfloatbuffer(); vertbuff.put(vertices); vertbuff.position(0); bytebuffer pbbuff = bytebuffer.allocate(pindex.length * 2); pbbuff.order(byteorder.nativeorder()); pbuff = pbbuff.asshortbuffer(); pbuff.put(pindex); pbuff.position(0); } public void draw(gl10 gl) { gl.glfrontface(gl10.gl_cw); gl.glenableclientstate(gl10.gl_vertex_array); gl.glvertexpointer(2, gl10.gl_float, 0, vertbuff); gl.gldrawelements(gl10.gl_triangles, pindex.length, gl10.gl_unsigned_short, pbuff); gl.gldisableclientstate(gl10.gl_vertex_array); } }
and glrendererex.java class
public class glrendererex implements renderer { private gltriangleex tri; public glrendererex() { tri = new gltriangleex(); } @override public void onsurfacecreated(gl10 gl, eglconfig eglconfig) { gl.gldisable(gl10.gl_dither); gl.glhint(gl10.gl_perspective_correction_hint, gl10.gl_fastest); gl.glclearcolor(.1f, 0f, .9f, 1f);// set background color gl.glcleardepthf(1f); } @override public void ondrawframe(gl10 gl) { gl.gldisable(gl10.gl_dither); gl.glclear(gl10.gl_color_buffer_bit | gl10.gl_depth_buffer_bit); gl.glmatrixmode(gl10.gl_modelview); gl.glloadidentity(); glu.glulookat(gl, 0, 0, -5, 0, 0, 0, 0, 2, 0); tri.draw(gl); } @override public void onsurfacechanged(gl10 gl, int width, int height) { gl.glviewport(0, 0, width, height); float ratio = (float) width / height; gl.glmatrixmode(gl10.gl_projection); gl.glloadidentity(); gl.glfrustumf(-ratio, ratio, -1, 1, 1, 25); } }
and logcat
02-08 12:11:01.244: i/activitymanager(58): starting activity: intent { cmp=com.android/.glexample } 02-08 12:11:01.305: d/dalvikvm(328): gc_external_alloc freed 1143 objects / 82584 bytes in 39ms 02-08 12:11:01.393: d/libegl(328): egl.cfg not found, using default config 02-08 12:11:01.393: d/libegl(328): loaded /system/lib/egl/libgles_android.so 02-08 12:11:01.534: i/debug(30): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 02-08 12:11:01.534: i/debug(30): build fingerprint: 'generic/google_sdk/generic/:2.2/frf91/43546:eng/test-keys' 02-08 12:11:01.534: i/debug(30): pid: 328, tid: 334 >>> com.android <<< 02-08 12:11:01.534: i/debug(30): signal 11 (sigsegv), fault addr 00000000 02-08 12:11:01.534: i/debug(30): r0 00001403 r1 00000003 r2 00000000 r3 00001403 02-08 12:11:01.534: i/debug(30): r4 00239480 r5 00000000 r6 00000003 r7 00239480 02-08 12:11:01.534: i/debug(30): r8 00000000 r9 00000000 10 00000000 fp 0012fbb8 02-08 12:11:01.534: i/debug(30): ip 00000000 sp 45f03d20 lr ac40604c pc ac40503c cpsr 60000010 02-08 12:11:01.594: i/debug(30): #00 pc 0000503c /system/lib/egl/libgles_android.so 02-08 12:11:01.594: i/debug(30): #01 pc 00006048 /system/lib/egl/libgles_android.so 02-08 12:11:01.594: i/debug(30): #02 pc 00020618 /system/lib/libandroid_runtime.so 02-08 12:11:01.594: i/debug(30): #03 pc 00013974 /system/lib/libdvm.so 02-08 12:11:01.594: i/debug(30): code around pc: 02-08 12:11:01.594: i/debug(30): ac40501c e5900548 e3a05b05 e2853003 e1500003 02-08 12:11:01.604: i/debug(30): ac40502c e2419003 1a000023 e1a05002 e3a0a000 02-08 12:11:01.604: i/debug(30): ac40503c e1d510b0 e1a00004 ebffff6e e1d510b2 02-08 12:11:01.604: i/debug(30): ac40504c e1a07000 e1a00004 ebffff6a e1d510b4 02-08 12:11:01.604: i/debug(30): ac40505c e1a06000 e1a00004 ebffff66 e5971020 02-08 12:11:01.604: i/debug(30): code around lr: 02-08 12:11:01.604: i/debug(30): ac40602c e59fe0ac e1a00007 e1a01006 e084400e 02-08 12:11:01.604: i/debug(30): ac40603c e0845105 e1a02008 e1a0e00f e595f2c0 02-08 12:11:01.604: i/debug(30): ac40604c e8bd81f0 e8bd81f0 e597098c e3a01b01 02-08 12:11:01.604: i/debug(30): ac40605c e281c008 e150000c 1affffe1 eafffff7 02-08 12:11:01.604: i/debug(30): ac40606c e3a01c05 e1a00007 e2811001 e8bd41f0 02-08 12:11:01.604: i/debug(30): stack: 02-08 12:11:01.604: i/debug(30): 45f03ce0 45f03d34 02-08 12:11:01.604: i/debug(30): 45f03ce4 80834ab3 /system/lib/libdvm.so 02-08 12:11:01.604: i/debug(30): 45f03ce8 8086deac /system/lib/libdvm.so 02-08 12:11:01.604: i/debug(30): 45f03cec 80846dad /system/lib/libdvm.so 02-08 12:11:01.614: i/debug(30): 45f03cf0 00000001 02-08 12:11:01.614: i/debug(30): 45f03cf4 0012fbb8 [heap] 02-08 12:11:01.614: i/debug(30): 45f03cf8 43e460f8 /dev/ashmem/mspace/dalvik-heap/2 (deleted) 02-08 12:11:01.614: i/debug(30): 45f03cfc 00239480 [heap] 02-08 12:11:01.614: i/debug(30): 45f03d00 ac41b858 /system/lib/egl/libgles_android.so 02-08 12:11:01.614: i/debug(30): 45f03d04 00001100 02-08 12:11:01.614: i/debug(30): 45f03d08 00000077 02-08 12:11:01.614: i/debug(30): 45f03d0c ac908e2c /system/lib/libpixelflinger.so 02-08 12:11:01.614: i/debug(30): 45f03d10 428a0ee8 02-08 12:11:01.614: i/debug(30): 45f03d14 00000000 02-08 12:11:01.614: i/debug(30): 45f03d18 df002777 02-08 12:11:01.614: i/debug(30): 45f03d1c e3a070ad 02-08 12:11:01.614: i/debug(30): #00 45f03d20 ac41b008 /system/lib/egl/libgles_android.so 02-08 12:11:01.614: i/debug(30): 45f03d24 ac41b018 /system/lib/egl/libgles_android.so 02-08 12:11:01.614: i/debug(30): 45f03d28 00000003 02-08 12:11:01.614: i/debug(30): 45f03d2c 00239480 [heap] 02-08 12:11:01.614: i/debug(30): 45f03d30 00000000 02-08 12:11:01.614: i/debug(30): 45f03d34 428a0ee8 02-08 12:11:01.614: i/debug(30): 45f03d38 428a0ed0 02-08 12:11:01.614: i/debug(30): 45f03d3c ac40604c /system/lib/egl/libgles_android.so 02-08 12:11:01.614: i/debug(30): #01 45f03d40 00118d78 [heap] 02-08 12:11:01.624: i/debug(30): 45f03d44 00000003 02-08 12:11:01.624: i/debug(30): 45f03d48 00000000 02-08 12:11:01.624: i/debug(30): 45f03d4c 00000004 02-08 12:11:01.624: i/debug(30): 45f03d50 45f03d80 02-08 12:11:01.624: i/debug(30): 45f03d54 ad32061c /system/lib/libandroid_runtime.so 02-08 12:11:02.084: i/bootreceiver(58): copying /data/tombstones/tombstone_09 dropbox (system_tombstone) 02-08 12:11:02.094: d/zygote(32): process 328 terminated signal (11) 02-08 12:11:02.174: d/dalvikvm(58): gc_for_malloc freed 2585 objects / 653024 bytes in 89ms 02-08 12:11:02.184: i/windowmanager(58): win death: window{4400b600 surfaceview paused=false} 02-08 12:11:02.184: i/windowmanager(58): win death: window{4400b9c0 com.android/com.android.glexample paused=false} 02-08 12:11:02.184: i/windowmanager(58): win death: window{43f5e388 com.android/com.android.menu paused=false} 02-08 12:11:02.184: i/activitymanager(58): process com.android (pid 328) has died. 02-08 12:11:02.203: i/activitymanager(58): start proc com.android activity com.android/.menu: pid=335 uid=10040 gids={3003, 1015} 02-08 12:11:02.343: i/usagestats(58): unexpected resume of com.android while resumed in com.android 02-08 12:11:02.354: i/activitymanager(58): displayed activity com.android/.menu: 168 ms (total 1103 ms) 02-08 12:11:02.564: w/inputmanagerservice(58): got remoteexception sending setactive(false) notification pid 328 uid 10040
it gives "signal 11" segmentation fault. so, programme trying access memory location either not have permission or null.
your code stuck @ gldrawelements(), because pbuff not allocated correctly.
replace this:
bytebuffer pbbuff = bytebuffer.allocate(pindex.length * 2);
with this:
bytebuffer pbbuff = bytebuffer.allocatedirect(pindex.length * 2);
and should work fine.
android opengl-es
No comments:
Post a Comment