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.util; // ww w .j a v a 2 s . com import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10; public class TextureRect { private float TABLE_UNIT_SIZE = 0.5f; private float TABLE_UNIT_HIGHT = 0.5f; private FloatBuffer mVertexBuffer;//??????????????? private FloatBuffer mTextureBuffer;//??????????????? int vCount=0; int texId; public TextureRect(float width,float height, float length,int texId,float[] texST) { this.texId=texId; //?????????????????================begin============================ vCount=6; float vertices[]=new float[] { -width*TABLE_UNIT_SIZE,height*TABLE_UNIT_HIGHT,-length*TABLE_UNIT_SIZE, -width*TABLE_UNIT_SIZE,-height*TABLE_UNIT_HIGHT,length*TABLE_UNIT_SIZE, width*TABLE_UNIT_SIZE,-height*TABLE_UNIT_HIGHT,length*TABLE_UNIT_SIZE, width*TABLE_UNIT_SIZE,-height*TABLE_UNIT_HIGHT,length*TABLE_UNIT_SIZE, width*TABLE_UNIT_SIZE,height*TABLE_UNIT_HIGHT,-length*TABLE_UNIT_SIZE, -width*TABLE_UNIT_SIZE,height*TABLE_UNIT_HIGHT,-length*TABLE_UNIT_SIZE, }; //??????????????????? //vertices.length*4?????????????????? ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); vbb.order(ByteOrder.nativeOrder());//?????????? mVertexBuffer = vbb.asFloatBuffer();//????Float????? mVertexBuffer.put(vertices);//???????????????????? mVertexBuffer.position(0);//?????????????? //?????????????????????????????????????????????ByteBuffer //??????????????ByteOrder????nativeOrder()????????????????? //?????????????????================end============================ ByteBuffer tbb = ByteBuffer.allocateDirect(texST.length*4); tbb.order(ByteOrder.nativeOrder());//?????????? mTextureBuffer = tbb.asFloatBuffer();//????int????? mTextureBuffer.put(texST);//??????????????????? mTextureBuffer.position(0);//?????????????? } public void drawSelf(GL10 gl) { gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);//?????????????? //???????????????????? gl.glVertexPointer ( 3, //????????????????3 xyz GL10.GL_FLOAT, //???????????????? GL_FLOAT 0, //?????????????????????? mVertexBuffer //???????????? ); //???????? gl.glEnable(GL10.GL_TEXTURE_2D); //???????????ST?????? gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); //????????????ST?????? gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer); //???????? gl.glBindTexture(GL10.GL_TEXTURE_2D, texId); //??????? gl.glDrawArrays ( GL10.GL_TRIANGLES, //????????????? 0, //??????? vCount //????????? ); } }