Perspective correct texturing of trapezoid in OpenGL ES 2.0

前端 未结 3 929
执念已碎
执念已碎 2020-11-27 05:00

I have drawn a textured trapezoid, however the result does not appear as I had intended.

Instead of appearing as a single unbroken quadrilateral, a discontinuity occ

3条回答
  •  感动是毒
    2020-11-27 05:46

    What you are trying here is Skewed texture. A sample fragment shader is as follows :

    precision mediump float;
    varying vec4 vtexCoords;
    uniform sampler2D sampler;
    
    void main()
    {
       gl_FragColor = texture2DProj(sampler,vtexCoords);
    }
    

    2 things which should look different are :

    1) We are using varying vec4 vtexCoords; . Texture co-ordinates are 4 dimensional. 2) texture2DProj() is used instead of texture2D()

    Based on length of small and large side of your trapezium you will assign texture co-ordinates. Following URL might help : http://www.xyzw.us/~cass/qcoord/

提交回复
热议问题