android - Moving from bitmap to OpenGL -


ok, time use opengl (gulp!) render sprites in apps (games), , forgetting bitmap.draw etc.

after trawling through hundreds of sites/blogs (well maybe) 'explaining' how code using opengl, have hit brick wall.

the problem apps functional , on market @ moment, latest app developed on htc desire hd, , getting many reports of bad performance on less powerful devices.

the obvious route move opengl. tutorial sites geared towards developing scratch. great starting new project, need 'retro-fit' apps. don't fancy rewriting scratch!

has had experience of this? thoughts hugely appreciated.

i did similar app , did receive large performance benefit. lot of 'should change' depends on how application structured.

for me hardest thing translating ui elements because had re-generate entire 'which control got touched' logic , setup text rendering. neither of these problems tough enough deal beakers i'd avoid them if can.

fortunately there sides. since app 2d can avoid complex parts of learning opengl, dealing 3d dimension! i'd start setting gl.surfaceview. use glortho setup extents of gl world, if game resolution independent should should have idea of how wide screen in 'independent' manner. setup glortho use same extents.

i created simple sprite class used rendering. sprite had simple vertex buffer members, had make 1 1 rect, used used scale setup size. (so if 30x30, set scale scalex=30 scaley=30).

it looked this

        bytebuffer vbb = bytebuffer.allocatedirect( mnumverts * 2 * 4 );         vbb.order( byteorder.nativeorder() );         mvtxbuf = vbb.asintbuffer();          vbb = bytebuffer.allocatedirect( mnumverts * 2 * 4 );         vbb.order( byteorder.nativeorder() );         mtexbuf = vbb.asintbuffer();          mvtxbuf.put( -fixed32.half ); mvtxbuf.put( -fixed32.half ); mtexbuf.put( 0 ); mtexbuf.put( fixed32.one );         mvtxbuf.put(  fixed32.half ); mvtxbuf.put( -fixed32.half ); mtexbuf.put( fixed32.one ); mtexbuf.put( fixed32.one );         mvtxbuf.put(  fixed32.half ); mvtxbuf.put(  fixed32.half ); mtexbuf.put( fixed32.one ); mtexbuf.put( 0 );          mvtxbuf.put( -fixed32.half ); mvtxbuf.put( -fixed32.half ); mtexbuf.put( 0 ); mtexbuf.put( fixed32.one );         mvtxbuf.put(  fixed32.half ); mvtxbuf.put(  fixed32.half ); mtexbuf.put( fixed32.one ); mtexbuf.put( 0 );                 mvtxbuf.put( -fixed32.half ); mvtxbuf.put(  fixed32.half ); mtexbuf.put( 0 ); mtexbuf.put( 0 );          mvtxbuf.position( 0 );                 mtexbuf.position( 0 ); 

(fixed32.half 0.5 in fixed point, can use 0.5 , change draw calls float instead of fixed)

with drawing code of...

        gl.glmatrixmode( gl10.gl_modelview );         gl.glloadidentity();         gl.glenableclientstate( gl10.gl_vertex_array );                          gl.glenableclientstate( gl10.gl_texture_coord_array );          gl.glcolor4f( 1.0f * thing.getalpha() , 1.0f * thing.getalpha() , 1.0f * thing.getalpha() , thing.getalpha() );            gl.gltranslatef( thing.getx(), thing.gety(), thing.getz() );         gl.glscalef( thing.getxscale(), thing.getyscale(), thing.getzscale() );          gl.glfrontface( gl10.gl_cw );         gl.glvertexpointer( 2, gl10.gl_fixed, 0, mdl.getvtxbuf() );          gl.gltexcoordpointer( 2, gl10.gl_fixed, 0, mdl.gettexbuf() );         // gl.glcolorpointer( 4, gl10.gl_float, 0, mcolorbuffer );         gl.gldrawarrays( gl10.gl_triangles, 0, mdl.getvtxcount() );  

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -