How to stretch the texture diagonally? Ie what would it look like a parallelogram

  • Use shaders. - Master Flomaster
  • Can an example of using shaders? - Vladislav

1 answer 1

Found a way! Who is interested

in Create

String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_worldView;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n" + "{ \n" + " v_color = vec4(1, 1, 1, 1); \n" + " v_texCoords = a_texCoord0; \n" + " gl_Position = u_worldView * a_position; \n" + "} \n" ; String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n" + "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n"+ "}"; mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute. ColorUnpacked(), VertexAttribute.TexCoords(0)); mesh.setIndices(new short[] {0, 1, 2, 2, 3, 0}); shader = new ShaderProgram(vertexShader, fragmentShader); 

In render

  sprite9.getTexture().bind(); shader.begin(); shader.setUniformMatrix("u_worldView",camera.combined); shader.setUniformi("u_texture", 0); for (int i=(int)(rect.getPosition().x+10);i<(int)(rect.getPosition().x+80);i++){ mesh.setVertices(new float[] {race[i].x, race[i].y-0.7f, 0, 1, 0, 1, 1, 0, 1, race[i].x, race[i].y, 0, 1, 1, 1, 1, 1, 0, race[i+1].x, race[i+1].y, 0, 1, 1, 1, 1, 1, 0, race[i+1].x, race[i+1].y-0.7f, 0, 1, 1, 1, 1, 0, 1 }); mesh.render(shader, GL20.GL_TRIANGLE_FAN); } shader.end(); 

I have painted the surface of the track. Che for the values ​​in the mesh and in the shaders, I do not know, can anyone explain in the comments enter image description here