In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to build OpenGL ES development environment in Android". In daily operation, I believe many people have doubts about how to build OpenGL ES development environment in Android. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to build OpenGL ES development environment in Android". Next, please follow the editor to study!
Declare the use of Declare OpenGL ES Use in the Manifest in OpenGL ES in Manifest
To use OpenGL ES 2.0 API in your application, you must add the following declaration to Manifest:
If texture compression is used in your application, you must declare the compression formats supported by the application to remind devices that do not support these formats not to try to run your application:
For more information about texture compression formats, please refer to the OpenGl ES Development Guide.
Create an Activity Create an Activity for OpenGL ES Graphics for OpenGL ES
Android applications that use OpenGL ES, like activities for other applications, have a user interface. The difference is what controls you use in the layout of activity. In many applications, you may use TextView,Button and ListView. In applications that use OpenGL ES, you can also add GLSurfaceView.
In the following sample code, a * implementation of Activity using GLSurfaceView as the main view is rendered:
Public class OpenGLES20 extends Activity {private GLSurfaceView mGLView; @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); / / Create a GLSurfaceView instance and set it / / as the ContentView for this Activity. MGLView = new MyGLSurfaceView (this); setContentView (mGLView);}}
Note: OpenGL ES 2.0 requires more than Android2.2 (API 8). Please make sure that the API setting of your Android project is correct.
Create a GLSurfaceView object Build a GLSurfaceView Object
GLSurfaceView is a special view that can draw OpenGL ES images. It has no processing function, and the images you draw are controlled by the GLSurfaceView.Renderer you set. In fact, the code for this object is simple, and you may prefer to create an undefined GLSurfaceView instance yourself rather than inherit it, but never do so. You need to inherit this class to capture touch events, which will be covered in the Responding_to_Touch_Events | Touch response lesson.
The necessary code for GLSurfaceView is minimal, and for a quick implementation, the most common approach is to create an inner class in activity:
Class MyGLSurfaceView extends GLSurfaceView {public MyGLSurfaceView (Context context) {super (context); / / Set the Renderer for drawing on the GLSurfaceView setRenderer (new MyRenderer ());}}
When using OpenGL ES 2.0, you must add one more sentence of code to your GLSurfaceView constructor to declare that you are using API for OpenGL ES 2.0:
/ / Create an OpenGL ES 2.0 context setEGLContextClientVersion (2)
Note: if you are using OpenGL ES 2.0 API, please make sure that you have made a declaration in the manifest of the application. For more information, please refer to the use of Declare OpenGL ES Use in the Manifest in the Manifest declaration of OpenGL ES
Using GLSurfaceView.RENDERMODE_WHEN_DIRTY, you can set the rendering mode implemented by GLSurfaceView: draw an attempt only when the graph data of the application changes. This setting is optional and is set as follows:
/ / Render the view only when there is a change in the drawing data setRenderMode (GLSurfaceView.RENDERMODE_WHEN_DIRTY)
This setting prevents the GLSurfaceView image from being redrawn until you call the equestRender () method, which is even more valuable in the sample application.
Create the renderer class Build a Renderer Class
The implementation of the GLSurfaceView.Renderer class or renderer makes applications that use OpenGL start to be interesting. This class controls what is associated with it can be drawn in GLSurfaceView. The renderer provides three methods for Android system calls to control what works and how it is drawn on GLSurfaceView.
* onSurfaceCreated ()-sets the OpenGL ES environment of the view, which needs only be called once
* onDrawFrame ()-called when each view is redrawn
* onSurfaceChanged ()-called when the geometry of the view changes, for example, the orientation of the device's screen changes
Here is a very basic implementation of the OpenGL ES renderer, with only a gray background drawn on GLSurfaceView:
Public class MyGL20Renderer implements GLSurfaceView.Renderer {public void onSurfaceCreated (GL10 unused, EGLConfig config) {/ / Set the background frame color GLES20.glClearColor (0.5f, 0.5f, 0.5f, 1.0f);} public void onDrawFrame (GL10 unused) {/ / Redraw background color GLES20.glClear (GLES20.GL_COLOR_BUFFER_BIT) } public void onSurfaceChanged (GL10 unused, int width, int height) {GLES20.glViewport (0,0, width, height);}}
This is everything introduced in this class. The above sample code creates a simple application: draw a gray background using OpenGL. Although the code doesn't do anything interesting, by building these classes, you lay the foundation for drawing images using OpenGL.
When using the API of OpengGL ES 2.0, you may wonder why these methods include the GL10 parameter, because the signature of these methods is to reuse the 2.0 API to keep the code of the Android framework simpler.
At this point, the study on "how to build an OpenGL ES development environment in Android" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.