美文网首页Unity基础入门分享
untiy使用GL简单画个线框

untiy使用GL简单画个线框

作者: BowenK | 来源:发表于2017-11-30 16:08 被阅读13次

由于最近做个功能,想要在屏幕上画个框框突出下 我要显示的东西,所以简单使用GL写了个画线框的方法,只要传入两个点就可以了

using UnityEngine;
using System.Collections;

public class DrawLine : MonoBehaviour {

public Material mat;
private Vector2 screenStartPos, screenEndPos;

void OnPostRender(Vector2 pos1, Vector2 pos2)
    {
        GL.PushMatrix();
        mat.SetPass(0);
        GL.LoadOrtho();
        GL.Begin(GL.LINES);
        GL.Color(Color.red);
        GL.Vertex3(pos1.x / Screen.width, pos1.y / Screen.height, 0);
        GL.Vertex3(pos2.x / Screen.width, pos1.y / Screen.height, 0);
        GL.Vertex3(pos2.x / Screen.width, pos1.y / Screen.height, 0);
        GL.Vertex3(pos2.x / Screen.width, pos2.y / Screen.height, 0);
        GL.Vertex3(pos2.x / Screen.width, pos2.y / Screen.height, 0);
        GL.Vertex3(pos1.x / Screen.width, pos2.y / Screen.height, 0);
        GL.Vertex3(pos1.x / Screen.width, pos2.y / Screen.height, 0);
        GL.Vertex3(pos1.x / Screen.width, pos1.y / Screen.height, 0);
        GL.End();
        GL.PopMatrix();
    }
}

相关文章

网友评论

    本文标题:untiy使用GL简单画个线框

    本文链接:https://www.haomeiwen.com/subject/aywvbxtx.html