Back to project page NotATop.
The source code is released under:
GNU General Public License
If you think the Android project NotATop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.gg.module; /*from www . jav a 2 s . c om*/ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10; import com.gg.util.Constant; public class DrawBackground { private FloatBuffer mVertexBuffer;//??????????????? private FloatBuffer mTextureBuffer;//??????????????? private int vCount;//????????????????????? int drawableId;//????ID public float mAngleX;//??X????????? public float mAngleY;//??Y????????? public float mAngleZ;//??Z????????? public DrawBackground(int drawableId) { this.drawableId=drawableId; //??????????????? initVertex(); //??????????????? initTexture(); } public void initVertex() { float x=Constant.LOGIC_WIDTH/2;//??????X?????????? float y=1f*2/2;//??????Y?????????? float z=0;//??????Z?????????? float[] vertices= {//?????????????????????????????????????? -x,y,z, -x,-y,z, x,y,z, -x,-y,z, x,-y,z, x,y,z, }; vCount=vertices.length/3;//???????? //??????????????????? //vertices.length*4????????Float?????? ByteBuffer vbb=ByteBuffer.allocateDirect(vertices.length*4); vbb.order(ByteOrder.nativeOrder());//?????????? mVertexBuffer=vbb.asFloatBuffer();//????float????? mVertexBuffer.put(vertices);//???????????????????? mVertexBuffer.position(0);//?????????????? } public void initTexture() {//?????????? float[] textures=new float[vCount*2];//?????????????????????2?? int temp=0; //???????????????????? textures[temp++]=0; textures[temp++]=0; textures[temp++]=0; textures[temp++]=1; textures[temp++]=1; textures[temp++]=0; //??????????????????? textures[temp++]=0; textures[temp++]=1; textures[temp++]=1; textures[temp++]=1; textures[temp++]=1; textures[temp++]=0; //??????????????????? //vertices.length*4????????Float?????? ByteBuffer tbb=ByteBuffer.allocateDirect(textures.length*4); tbb.order(ByteOrder.nativeOrder());//?????????? mTextureBuffer=tbb.asFloatBuffer();//????float????? mTextureBuffer.put(textures);//???????????????????? mTextureBuffer.position(0);//?????????????? } public void drawSelf(GL10 gl) { gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);//?????????? gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);//???????????????????? gl.glEnable(GL10.GL_TEXTURE_2D);//???????? gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);//???????????? gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);//?????????????????? gl.glBindTexture(GL10.GL_TEXTURE_2D, drawableId);//???? gl.glRotatef(mAngleX, 1, 0, 0);//??X?????mAngleX?? gl.glRotatef(mAngleY, 0, 1, 0);//??Y?????mAngleY?? gl.glRotatef(mAngleZ, 0, 0, 1);//??Z?????mAngleZ?? gl.glDrawArrays(GL10.GL_TRIANGLES, 0, vCount);//??????? gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); } public int getDrawableId() { return drawableId; } public void setDrawableId(int drawableId) { this.drawableId = drawableId; } }