: The right side of the text bar moves up and down, no text will automatically stop moving. This is different from the texture movement I wrote before, which is the loop movement, this time the positioning move.
Vertex shader:
Uniform mat4 umvpmatrix;attribute vec3 aposition;attribute vec2 atexcoor;varying vec2 vtexturecoord;void Main () { GL _POSITION=UMVPMATRIX*VEC4 (aposition,1); Vtexturecoord=atexcoor;}
Slice shader:
Precision Mediump float;varying vec2 vtexturecoord;uniform sampler2d stexture;uniform float uspan;void main () { vec2 ST_RESULT=VEC2 (0,0); st_result.x=vtexturecoord.x; St_result.y=vtexturecoord.y+uspan; Gl_fragcolor=texture2d (Stexture,st_result);}
Java code: (here is the core)
Package Com.hl.paints;import Java.nio.bytebuffer;import Java.nio.byteorder;import java.nio.floatbuffer;import Com.hl.utils.matrixstate;import Android.opengl.gles20;public class Drawrectmovestop {int MProgram;int Mumvpmatrixhandle;int mapositionhandle;int Matexcoorhandle;int Muspanhandle; Floatbuffer Mvertexbuffer; Floatbuffer mtexcoorbuffer;int vcount=0;public drawrectmovestop (float width,float height,float s,float t,int mProgram) {//TODO auto-generated constructor Stubinitvertex (width,height,s,t); Initshader (Mprogram);} private void Initvertex (float width, float height,<span style= "color: #ff0000;" >float s,float t</span>) {//The incoming texture, the purpose is to be in the beginning is not the entire picture into a rectangular box, but a part//TODO auto-generated method stubvcount = 6; float W = width/2;float h = height/2;float vertices[] = new float[] {-W, H, 0,-w,-H, 0, W,-H, 0, W,-H, 0, W, H, 0,-w, H, 0,}; Bytebuffer VBB = Bytebuffer.allocatedirect (Vertices.length * 4); Vbb.order (Byteorder.nativeorder ()); MVertexBuffer = Vbb.asfloatbuffer (); MvertexbUffer.put (vertices); mvertexbuffer.position (0); float texcoor[] = new float[] {0, 0, 0, T, S, T, S, T, S, 0, 0, 0}; Bytebuffer CBB = Bytebuffer.allocatedirect (Texcoor.length * 4); Cbb.order (Byteorder.nativeorder ()); MTexCoorBuffer = Cbb.asfloatbuffer (); Mtexcoorbuffer.put (Texcoor); mtexcoorbuffer.position (0);} private void Initshader (int mprogram) {//TODO auto-generated Method stubthis.mprogram = Mprogram;mumvpmatrixhandle = GLES 20.glGetUniformLocation (Mprogram, "Umvpmatrix"); mapositionhandle = Gles20.glgetattriblocation (Mprogram, "aposition "); Matexcoorhandle = Gles20.glgetattriblocation (Mprogram," Atexcoor "); Muspanhandle=gles20.glgetuniformlocation ( Mprogram, "Uspan");} public void drawself (int texid,float currstart) {gles20.gluseprogram (Mprogram); GLES20.GLUNIFORMMATRIX4FV (Mumvpmatrixhandle, 1, False, Matrixstate.getfinalmatrix (), 0); Gles20.glvertexattribpointer (Mapositionhandle, 3, Gles20.gl_float, False, 3*4, Mvertexbuffer); Gles20.glvertexattribpointer (Matexcoorhandle, 2, Gles20.gl_float, FAlse, 2*4, Mtexcoorbuffer); Gles20.glenablevertexattribarray (Mapositionhandle); Gles20.glenablevertexattribarray (Matexcoorhandle); gles20.gluniform1f (Muspanhandle, Currstart); Gles20.glactivetexture (GLES20.GL_TEXTURE0); Gles20.glbindtexture (gles20.gl_texture_2d, TEXID); Gles20.gldrawarrays (gles20.gl_triangles, 0, Vcount);}}
Using code:
Private Drawrectmovestop Benrighttext; Button_ben_right3_width = 2.0f * ratio * 0.23F; Button_ben_right3_height = 1.4f; Button_ben_right3_xoffset = ratio-2.0f * ratio * 0.23F/2; Button_ben_right3_yoffset = 1.0f-0.15f-0.37f-0.02f-0.7f;benrighttext = new Drawrectmovestop (BUTTON_BEN_RIGHT3_WIDT H, Button_ben_right3_height,<span style= "color: #ff0000;" > 1.0f, 0.7f</span>, Shadermanager.getmovetextureshaderprogram ());
1.0f and 0.7f are calculated based on the texture picture and width. The right part of the text is in the form of a picture.
<pre name= "code" class= "java" > Matrixstate.pushmatrix (); Matrixstate.translate (Button_ben_right3_xoffset, Button_ben_right3_yoffset, 0); Benrighttext.drawself (rText[ Condition], textyoffset); Matrixstate.popmatrix ();
private float textyoffset = 0;
<span style= "color: #ff0000;" >if (Utilconfigarea.isinarea (x, Y, area_ben_right3)) {//ontouchevent Action_move:textyoffset = dy * TOUCH_SCALE_ FACTOR * 0.002F;IF (Textyoffset > 0.3f) {textyoffset = 0.3f;} if (Textyoffset < 0.0f) {textyoffset = 0.0f;}} </span>
Note: Some of the methods used in this article are mentioned in my other blog posts, if used, please check the relevant blog post.
Android Texture Fixed distance movement