Search Unity

GL and texture coordinates

Discussion in 'Shaders' started by mouurusai, Oct 24, 2014.

  1. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    Hello everyone! How to draw with gl triangles with certain texture coordinates?
    When I use this code, a circle texture looks like stripes, but I expected this will become tiled circles without any distortion. Thanks in advance!
    stripes.jpg
    Code (csharp):
    1.  
    2. usingUnityEngine;
    3.  
    4. [ExecuteInEditMode]
    5. publicclass GlUvTest:MonoBehaviour
    6. {
    7.    public Material mat;
    8.  
    9.    void Update()
    10.    {
    11.        transform.position=new Vector3(0, 5.621685f, -8.10467f);
    12.    }
    13.  
    14.    void OnPostRender()
    15.    {
    16.        if(mat==null)
    17.             return;
    18.  
    19.         mat.SetPass(0);
    20.        
    21.         GL.Begin(GL.TRIANGLES);
    22.         GL.Color(Color.white);
    23.  
    24.  
    25.         GL.Vertex3(0, 1, 0);
    26.         GL.TexCoord2(0, 1);
    27.  
    28.         GL.Vertex3(0.5f, 10f, 0);
    29.         GL.TexCoord2(0.5f, 10);
    30.  
    31.         GL.Vertex3(1, 1, 0);
    32.         GL.TexCoord2(1, 1);
    33.  
    34.         GL.End();
    35.    }
    36. }
    37.  
    38.  
     
  2. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    No one knows?