java基于OpenGL ES实现渲染实例
本文实例讲述了java基于OpenGLES实现渲染的方法。分享给大家供大家参考。具体如下:
1.Run.java文件:
packagenet.obviam.opengl; importandroid.app.Activity; importandroid.opengl.GLSurfaceView; importandroid.os.Bundle; importandroid.view.Window; importandroid.view.WindowManager; publicclassRunextendsActivity{ /**TheOpenGLview*/ privateGLSurfaceViewglSurfaceView; /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //requestingtoturnthetitleOFF requestWindowFeature(Window.FEATURE_NO_TITLE); //makingitfullscreen getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); //InitiatetheOpenGLviewand //createaninstancewiththisactivity glSurfaceView=newGLSurfaceView(this); //setourrenderertobethemainrendererwith //thecurrentactivitycontext glSurfaceView.setRenderer(newGlRenderer()); setContentView(glSurfaceView); } /**RemembertoresumetheglSurface*/ @Override protectedvoidonResume(){ super.onResume(); glSurfaceView.onResume(); } /**AlsopausetheglSurface*/ @Override protectedvoidonPause(){ super.onPause(); glSurfaceView.onPause(); } }
2.GlRenderer.java文件:
importjavax.microedition.khronos.egl.EGLConfig; importjavax.microedition.khronos.opengles.GL10; importandroid.opengl.GLSurfaceView.Renderer; publicclassGlRendererimplementsRenderer{ @Override publicvoidonDrawFrame(GL10gl){ } @Override publicvoidonSurfaceChanged(GL10gl,intwidth,intheight){ } @Override publicvoidonSurfaceCreated(GL10gl,EGLConfigconfig){ } }
希望本文所述对大家的java程序设计有所帮助。