Steps to call OpenGL ES2.0 functions in eclipse via the Android emulator

Source: Internet
Author: User

Original address:

Steps to invoke OpenGL ES2.0 function via Android emulator in Eclipse-network resources are unlimited-blog channel-csdn.net
http://blog.csdn.net/fengbingchun/article/details/11192189

1, first in accordance with the http://blog.csdn.net/fengbingchun/article/details/10439281 operation to build a basic Android development environment;

2. Open eclipse,-->window-->androidvirtual device MANAGER-->NEW-->AVD name:android_opengles, device: Galaxynexus (4.65 ", 720*1280:xhdpi), target:android 4.3-api level 18; Emulation options Check the use HOSTGPU, click OK;

3. Select the new Android_opengles,-->start-->launch, and if the run fails, C:\Users\Spring\.android\avd\Android_ it Opengles.avd folder in the Config.ini file, will hw.ramsize=1024 changed to HW.RAMSIZE=1024MB, save, run again will be successful;

4, create a new project, to determine whether the device supports OpenGL ES2.0;

5. File-->new-->project...-->android-->android applicationproject-->next-->application Name: Firstopenglproject,package name:com.firstopenglproject.android,minimumrequired SDK:API, Android 2.3.3 ( Gingerbread) (This was the minimum versionwith full OpenGL ES 2.0 support), next--> do not tick create Customlauncher icon, tick create Activity,next--> Select Blank Activity,next-->activity name:firstopenglprojectactivity-->finish;

6. Open the Src-->com.firstopenglproject.android-->firstopenglprojectactivity.java and change its contents to:

 Packagecom.firstopenglproject.android;Importandroid.app.Activity;ImportAndroid.app.ActivityManager;ImportAndroid.content.Context;ImportAndroid.content.pm.ConfigurationInfo;ImportAndroid.opengl.GLSurfaceView;ImportAndroid.os.Build;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.widget.Toast; Public classFirstopenglprojectactivityextendsActivity {PrivateGlsurfaceview Glsurfaceview; Private BooleanRendererset =false; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //Setcontentview (r.layout.activity_first_open_glproject);Glsurfaceview =NewGlsurfaceview ( This); FinalActivitymanager Activitymanager =(Activitymanager) Getsystemservice (Context.activity_service); FinalConfigurationinfo Configurationinfo =Activitymanager.getdeviceconfigurationinfo (); Final BooleanSUPPORTSES2 =configurationinfo.reqglesversion>= 0x20000 | | (Build.VERSION.SDK_INT >=Build.version_codes. ICE_CREAM_SANDWICH_MR1&& (Build.FINGERPRINT.startsWith ("GENERIC")                      || Build.FINGERPRINT.startsWith ("Unknown")                      || Build.MODEL.contains ("Google_sdk")                      || Build.MODEL.contains ("Emulator")                      || Build.MODEL.contains ("Android SDK built for x86"))); if(SUPPORTSES2) {//Request an OpenGL ES 2.0 compatible context.Glsurfaceview.seteglcontextclientversion (2); //Assign our renderer.Glsurfaceview.setrenderer (Newfirstopenglprojectrenderer ()); Rendererset=true; } Else{Toast.maketext ( This, "This device does not support OpenGL ES 2.0.", Toast.length_long). Show (); return;    } setcontentview (Glsurfaceview); } @Overrideprotected voidOnPause () {Super. OnPause (); if(Rendererset) {glsurfaceview.onpause (); }} @Overrideprotected voidOnresume () {Super. Onresume (); if(Rendererset) {glsurfaceview.onresume (); }    }}

7, select Com.firstopenglproject.android, right click-->new-->class,name:firstopenglprojectrenderer-->finish, the content is:

 Packagecom.firstopenglproject.android;Import StaticAndroid.opengl.GLES20.GL_COLOR_BUFFER_BIT;Import Staticandroid.opengl.GLES20.glClear;Import StaticAndroid.opengl.GLES20.glClearColor;Import StaticAndroid.opengl.GLES20.glViewport;ImportJavax.microedition.khronos.egl.EGLConfig;Importjavax.microedition.khronos.opengles.GL10;ImportAndroid.opengl.GLSurfaceView.Renderer; Public classFirstopenglprojectrendererImplementsRenderer {@Override Public voidonsurfacecreated (GL10 glunused, EGLConfig config) {glclearcolor (1.0f, 0.0f, 0.0f, 0.0f); } @Override Public voidOnsurfacechanged (GL10 glunused,intWidthintheight) {        //Set the OpenGL viewport to fill the entire surface.Glviewport (0, 0, width, height); }    /*** Ondrawframe is called whenever a new frame needs to be drawn.     Normally, * This is do at the "refresh rate" of the screen. */@Override Public voidondrawframe (GL10 glunused) {//Clear the rendering surface.glclear (gl_color_buffer_bit); }}

8, select the project, right--->run as-->android application, will display a blank red screen.

References: "OpenGL ES 2.0 for Android"

Steps to call OpenGL ES2.0 functions in eclipse via the Android emulator

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.