OpenGL used on Android

Source: Internet
Author: User

Public class glsurfaceviewactivity extends activity {
 
Private myglsurfaceview mglsurfaceview;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Mglsurfaceview = new myglsurfaceview (this );
Setcontentview (mglsurfaceview );
// Setcontentview (R. layout. Main );
}
}
Public class myglsurfaceview extends glsurfaceview {
Private myglrenderer mrender;
 
Public myglsurfaceview (context ){
Super (context );
// Todo auto-generated constructor stub
Mrender = new myglrenderer ();
Setrenderer (mrender); // specify the mrender object. This mrender object is used to draw 3D images in glsurfaceview.
}
}
Public class myglrenderer implements Renderer {// instantiate OpenGL. glsurfaceview. Renderer requires three methods,
Public void ondrawframe (gl10 GL); Draws the current frame of glsurfaceview.
Public void onsurfacechanged (gl10 GL, int width, int height): gl10 is the paint brush, which is called back when the glsurfaceview size changes.
Public void onsurfacecreated (gl10 GL, eglconfig config): callback when glsurfaceview is created.
Public void onsurfacecreated (gl10 GL, eglconfig config ){
// Todo auto-generated method stub

Loadgif ("Data/APP/girl.gif ");
Gl. glable (gl11.gl _ dither); // enable anti-Jitter
Gl. gldisable (gl11.gl _ lighting );
// Set the system's correction to a certain aspect. Here, the perspective correction is made.
Gl. glhint (gl10.gl _ perspctive_correction_hint, ggl10.gl _ fastest );
// Enable textures. Enable texture Paster
Gl. glable (gl11.gl _ texture_2d );
Gl. gltexenvf (gl11.gl _ texture_env, gl11.gl _ texture_env_color, gl11.gl _ replace );

// Set up state for multitexture operations. Since multitexture is
// Currently used
// Only for layered crossfades the needed State can be factored out
// One-time
// Initialization. This section may need to be folded into drawmixed2d ()
// If multitexture
// Is used for other effects.

// Enable vertex Arrays
Gl. glableclientstate (gl11.gl _ vertex_array );

// Enable depth test.
Gl. glable (gl11.gl _ depth_test );
Gl. gldepthfunc (gl11.gl _ lequal );


// Set the blend function for premultiplied Alpha.
Gl. glable (gl10.gl _ blend );
Gl. glblendfunc (gl11.gl _ src_alpha, gl11.gl _ one_minus_src_alpha );

// Set the background color.
Gl. glclearcolor (0.0f, 0.0f, 0.0f, 0.0f );
Gl. glclear (gl11.gl _ color_buffer_bit );
}
Public void onsurfacechanged (gl10 GL, int width, int height ){
// Todo auto-generated method stub
Final float znear = 0.1f;
Final float zfar = 100366f;
Gl. glviewport (0, 0, width, height );
Gl. glmatrixmode (gl11.gl _ projection );
Gl. glloadidentity ();
Glu. gluperspective (GL, 45.0f, (float) width/height, znear, zfar );
Gl. glmatrixmode (gl11.gl _ modelview );
}
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.