Android OpenGL学习 三角形的绘制.
2010-07-15 21:05:00 来源:WEB开发网前面讲了一些Android OpenGl 的概念问题,这一节讲给大家讲一下如何画一个三角现出来.
一、新建一个Android工程命名为:OpenGL_Lesson2.
二、修改OpenGL_Lesson2.java代码如下:
view plaincopy to clipboardprint?
package com.android.tutor;
import android.app.Activity;
import android.os.Bundle;
public class OpenGL_Lesson2 extends Activity {
private OpenGlView mOpenGlView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mOpenGlView = new OpenGlView(this);
setContentView(mOpenGlView);
}
}
三、新建一个类OpenGlView.java继承与GLSurfaceView,代码如下:
view plaincopy to clipboardprint?
package com.android.tutor;
import android.content.Context;
import android.opengl.GLSurfaceView;
public class OpenGlView extends GLSurfaceView {
private OpenGlRender mOpenGlRender;
public OpenGlView(Context context) {
super(context);
mOpenGlRender = new OpenGlRender();
setRenderer(mOpenGlRender);
}
}
四、新建一个OpenGlRender.java类继承与Renderer,代码如下:
view plaincopy to clipboardprint?
package com.android.tutor;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView.Renderer;
public class OpenGlRender implements Renderer {
private float _red = 0f;
private float _green = 25f;
private float _blue = 200f;
private ShortBuffer _indexBuffer;
private FloatBuffer _vertexBuffer;
更多精彩
赞助商链接