Android texture fixed distance movement, android texture fixed Distance

Source: Internet
Author: User

Android texture fixed distance movement, android texture fixed Distance

: Move up and down the text bar on the right. If no text is displayed, it will automatically stop moving. This is different from the texture movement I wrote earlier. The previous movement is loop movement, and this time it is positioning and moving.


Vertex shader:

uniform mat4 uMVPMatrix;attribute vec3 aPosition;attribute vec2 aTexCoor;varying vec2 vTextureCoord;void main(){   gl_Position=uMVPMatrix*vec4(aPosition,1);   vTextureCoord=aTexCoor;}

Fragment coloring tool:

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 functions {int mProgram; int functions; int maPositionHandle; int maTexCoorHandle; int muSpanHandle; FloatBuffer mVertexBuffer; FloatBuffer mTexCoorBuffer; int vCount = 0; public functions (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>) {// texture input, the purpose is to put the entire image into a rectangular box at the beginning, but a part of it // 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,}; 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, 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; histogram = average (mProgram, "uMVPMatrix"); maPositionHandle = average (mProgram, "aPosition"); maTexCoorHandle = average (mProgram, "aTexCoor "); muSpanHandle = aggregate (mProgram, "uSpan");} public void drawSelf (int texId, float currStart) {gles?gluseprogram (mProgram); Aggregate (muMVPMatrixHandle, 1, false, MatrixState. getFinalMatrix (), 0); Aggregate (maPositionHandle, 3, gles0000gl _ FLOAT, false, 3*4, mVertexBuffer); Aggregate (maTexCoorHandle, 2, gles0000gl _ FLOAT, false, 2*4, mTexCoorBuffer); Second (maPositionHandle); Second (second); Second (muSpanHandle, currStart); Second (gles‑gl _ TEXTURE0); Second (gles‑gl _ TEXTURE_2D, texId ); gles1_gldrawarrays (gles1_gl _ TRIANGLES, 0, vCount );}}

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_WIDTH, 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 image and width. The text on the right is in the image format.
        <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 methods are used in this article. As mentioned in my other blog posts, if you want to use them, please refer to relevant blog posts.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.