android下的openGL开发

 我来答
peterliu01
2011-12-25 · TA获得超过787个赞
知道小有建树答主
回答量:286
采纳率:100%
帮助的人:212万
展开全部
  这个建议买本教材看看,现在这样的教材很多。

  OpenGL ES 2.0

  In this document
  Create an Activity with GLSurfaceView
  Draw a Shape on GLSurfaceViewDefine a Triangle
  Draw the Triangle

  Apply Projection and Camera Views
  Add Motion
  Respond to Touch Events

  Related Samples
  API Demos - graphics
  OpenGL ES 2.0 Sample
  TouchRotateActivity

  See also
  3D with OpenGL
  OpenGL ES 1.0

  This tutorial shows you how to create a simple Android application that uses the OpenGL ES 2.0 API to perform some basic graphics operations. You'll learn how to:
  •Create an activity using GLSurfaceView and GLSurfaceView.Renderer
  •Create and draw a graphic object
  •Define a projection to correct for screen geometry
  •Define a camera view
  •Rotate a graphic object
  •Make graphics touch interactive

  The Android framework supports both the OpenGL ES 1.0/1.1 and OpenGL ES 2.0 APIs. You should carefully consider which version of the OpenGL ES API (1.0/1.1 or 2.0) is most appropriate for your needs. For more information, see Choosing an OpenGL API Version. If you would prefer to use OpenGL ES 1.0, see the OpenGL ES 1.0 tutorial.

  Before you start, you should understand how to create a basic Android application. If you do not know how to create an app, follow the Hello World Tutorial to familiarize yourself with the process.

  Caution: OpenGL ES 2.0 is currently not supported by the Android Emulator. You must have a physical test device running Android 2.2 (API Level 8) or higher in order to run and test the example code in this tutorial.

  Create an Activity with GLSurfaceView

  To get started using OpenGL, you must implement both a GLSurfaceView and a GLSurfaceView.Renderer. The GLSurfaceView is the main view type for applications that use OpenGL and the GLSurfaceView.Renderer controls what is drawn within that view. (For more information about these classes, see the 3D with OpenGL document.)

  To create an activity using GLSurfaceView:
  1.Start a new Android project that targets Android 2.2 (API Level 8) or higher.
  2.Name the project HelloOpenGLES20 and make sure it includes an activity called HelloOpenGLES20.
  3.Modify the HelloOpenGLES20 class as follows: package com.example.android.apis.graphics;import android.app.Activity;import android.content.Context;import android.opengl.GLSurfaceView;import android.os.Bundle;public class HelloOpenGLES20 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 HelloOpenGLES20SurfaceView(this); setContentView(mGLView); } @Override protected void onPause() { super.onPause(); // The following call pauses the rendering thread. // If your OpenGL application is memory intensive, // you should consider de-allocating objects that // consume significant memory here. mGLView.onPause(); } @Override protected void onResume() { super.onResume(); // The following call resumes a paused rendering thread. // If you de-allocated graphic objects for onPause() // this is a good place to re-allocate them. mGLView.onResume(); }} class HelloOpenGLES20SurfaceView extends GLSurfaceView { public HelloOpenGLES20SurfaceView(Context context){ super(context); // Create an OpenGL ES 2.0 context. setEGLContextClientVersion(2); // Set the Renderer for drawing on the GLSurfaceView setRenderer(new HelloOpenGLES20Renderer()); }}
  Note: You will get a compile error for the HelloOpenGLES20Renderer class reference. That's expected; you will fix this error in the next step.

  As shown above, this activity uses a single GLSurfaceView for its view. Notice that this activity implements crucial lifecycle callbacks for pausing and resuming its work.

  The HelloOpenGLES20SurfaceView class in this example code above is just a thin wrapper for an instance of GLSurfaceView and is not strictly necessary for this example. However, if you want your application to monitor and respond to touch screen events—and we are guessing you do—you must extend GLSurfaceView to add touch event listeners, which you will learn how to do in the Reponding to Touch Events section.

  In order to draw graphics in the GLSurfaceView, you must define an implementation of GLSurfaceView.Renderer. In the next step, you create a renderer class to complete this OpenGL application.

  4.Create a new file for the following class HelloOpenGLES20Renderer, which implements the GLSurfaceView.Renderer interface: package com.example.android.apis.graphics;import javax.microedition.khronos.egl.EGLConfig;import javax.microedition.khronos.opengles.GL10;import android.opengl.GLES20;import android.opengl.GLSurfaceView;public class HelloOpenGLES20Renderer 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 | GLES20.GL_DEPTH_BUFFER_BIT); } public void onSurfaceChanged(GL10 unused, int width, int height) { GLES20.glViewport(0, 0, width, height); } }
  This minimal implementation of GLSurfaceView.Renderer provides the code structure needed to use OpenGL drawing methods:
  ◦onSurfaceCreated() is called once to set up the GLSurfaceView environment.
  ◦onDrawFrame() is called for each redraw of the GLSurfaceView.
  ◦onSurfaceChanged() is called if the geometry of the GLSurfaceView changes, for example when the device's screen orientation changes.

  For more information about these methods, see the 3D with OpenGL document.

  The code example above creates a simple Android application that displays a grey screen using OpenGL ES 2.0 calls. While this application does not do anything very interesting, by creating these classes, you have layed the foundation needed to start drawing graphic elements with OpenGL ES 2.0.

  If you are familiar with the OpenGL ES APIs, these classes should give you enough information to use the OpenGL ES 2.0 API and create graphics. However, if you need a bit more help getting started with OpenGL, head on to the next sections for a few more hints.

  Note: If your application requires OpenGL 2.0, make sure you declare this in your manifest:
  <!-- Tell the system this app requires OpenGL ES 2.0. --> <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  For more information, see OpenGL manifest declarations in the 3D with OpenGL document.

参考资料: http://developer.android.com/resources/tutorials/opengl/opengl-es20.html

浙江启扬智能科技有限公司
2023-06-12 广告
Android和ARM、Linux之间存在密切的联系。Android是一种基于Linux内核的嵌入式智能操作系统,它采用了ARM处理器作为其主要处理器架构。Android的内核和许多应用程序都是基于ARM架构编写的,包括处理器和内存管理器。... 点击进入详情页
本回答由浙江启扬智能科技有限公司提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式