Created
June 30, 2017 10:11
-
-
Save flushpot1125/48c0e20a1d33a48350c4170955b4582e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class GLTest : MonoBehaviour { | |
static Material lineMaterial; | |
static void CreateLineMaterial () | |
{ | |
if (!lineMaterial){ | |
// Unity has a built-in shader that is useful for drawing | |
// simple colored things. | |
Shader shader = Shader.Find ("Hidden/Internal-Colored"); | |
lineMaterial = new Material (shader); | |
lineMaterial.hideFlags = HideFlags.HideAndDontSave; | |
// Turn on alpha blending | |
lineMaterial.SetInt ("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); | |
lineMaterial.SetInt ("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); | |
// Turn backface culling off | |
lineMaterial.SetInt ("_Cull", (int)UnityEngine.Rendering.CullMode.Off); | |
// Turn off depth writes | |
lineMaterial.SetInt ("_ZWrite", 0); | |
} | |
} | |
public void OnRenderObject (){ | |
CreateLineMaterial (); | |
/*定型フォーマットのようなもの*/ | |
lineMaterial.SetPass (0); | |
GL.PushMatrix (); | |
GL.MultMatrix (transform.localToWorldMatrix); | |
/**/ | |
GL.Begin (GL.LINES); | |
GL.Color (new Color (1.0f, 1.0f, 0, 0.8f));//以下は黄色 | |
//GL.Color (new Color (255, 255, 0, 0.8f));//0-255の書き方にすると、色鮮やかになる。正しい使用法かは不明 | |
/*始点、終点を指定していく*/ | |
GL.Vertex3(-4, 0, 25); | |
GL.Vertex3(0, 4, 25); | |
GL.Vertex3(0, 4, 25); | |
GL.Vertex3(3, 7, 25); | |
GL.Vertex3(3, 7, 25); | |
GL.Vertex3(7, 10, 25); | |
GL.Vertex3(7, 10, 25); | |
GL.Vertex3(11, 12, 25); | |
/*色を変えたい時は、GL.Colorを再度指定し直す*/ | |
GL.Color (new Color (0.0f, 1.0f, 0.25f, 0.8F));//以下は緑色 | |
//横軸 | |
GL.Vertex3(-7, -2, 25); | |
GL.Vertex3(14, -2, 25); | |
//縦軸 | |
GL.Vertex3 (-7, -2, 25); | |
GL.Vertex3 (-7, 15, 25); | |
GL.End (); | |
GL.PopMatrix (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment