首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

andorid openGL 的简略使用

2012-07-27 
andorid openGL 的简单使用mainActivity:public class OpenGLDemoActivity extends Activity {public clas

andorid openGL 的简单使用

mainActivity:public class OpenGLDemoActivity extends Activity {

public class OpenGLRender implements Renderer {@Overridepublic void onDrawFrame(GL10 gl) {// TODO Auto-generated method stubByteBuffer vbb= ByteBuffer.allocateDirect(vertexArray.length*4);vbb.order(ByteOrder.nativeOrder());FloatBuffer vertex = vbb.asFloatBuffer();vertex.put(vertexArray);vertex.position(0);gl.glLoadIdentity();gl.glTranslatef(0, 0, -4);gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertex);index++;index%=10;switch(index){case 0:case 1:case 2:gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);gl.glDrawArrays(GL10.GL_LINES, 0, 4);break;case 3:case 4:case 5:gl.glColor4f(0.0f, 1.0f, 0.0f, 1.0f);gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 4);break;case 6:case 7:case 8:case 9:gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);break;}gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);}@Overridepublic void onSurfaceChanged(GL10 arg0, int width, int height) {// TODO Auto-generated method stubarg0.glViewport(0, 0, width, height);}@Overridepublic void onSurfaceCreated(GL10 gl, EGLConfig arg1) {// TODO Auto-generated method stub// gl.glClearColor(0.9f, 0.2f, 0.2f, 1.0f);      // gl.glClear(GL10.GL_COLOR_BUFFER_BIT);  }float vertexArray[] = {-0.8f, -0.4f * 1.732f, 0.0f,-0.4f, 0.4f * 1.732f, 0.0f,0.0f, -0.4f * 1.732f, 0.0f,0.4f, 0.4f * 1.732f, 0.0f,}; int index=0;

?

?

参考自:eoeAndroid上的文章

热点排行