untiy GLで簡単に線枠を描く
1039 ワード
最近機能して、画面に枠を描いて私が表示したいものを強調したいので、簡単にGLを使って線枠を書く方法を使って、2つの点を伝えればいいのです
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();
}
}