お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Closemode | プリミティブを描画: TRIANGLES, TRIANGLE_STRIP, QUADS, LINES. |
3D プリミティブの描画を開始します
これはOpenGLでの glBegin
; と同じような
機能性を持つものです。GL.BeginとGL.Endの間で
GL.Vertex、 GL.Color、 GL.TexCoord その他の即時描画系の機能の呼び出しが
有効になります。
プリミティブを描画するときにはカリングについて注意しなければいけません。カリングのルールとして
「ゲームの実行中は異なるグラフィックスAPIに依存している可能性がある」というのがあります。ほとんどの場合で
最も安全な方法は、シェーダの Cull Off
コマンドを使用することです。
See Also: GL.End
// Draws a Triangle, a Quad and a line // with different colors var mat : Material; function OnPostRender() { if (!mat) { Debug.LogError("Please Assign a material on the inspector"); return; } GL.PushMatrix(); mat.SetPass(0); GL.LoadOrtho(); GL.Begin(GL.TRIANGLES); // Triangle GL.Color(Color(1,1,1,1)); GL.Vertex3(0.50,0.25,0); GL.Vertex3(0.25,0.25,0); GL.Vertex3(0.375,0.5,0); GL.End(); GL.Begin(GL.QUADS); // Quad GL.Color(Color(0.5,0.5,0.5,1)); GL.Vertex3(0.5,0.5,0); GL.Vertex3(0.5,0.75,0); GL.Vertex3(0.75,0.75,0); GL.Vertex3(0.75,0.5,0); GL.End(); GL.Begin(GL.LINES); // Line GL.Color(Color(0,0,0,1)); GL.Vertex3(0,0,0); GL.Vertex3(0.75,0.75,0); GL.End(); GL.PopMatrix(); }
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Material mat; void OnPostRender() { if (!mat) { Debug.LogError("Please Assign a material on the inspector"); return; } GL.PushMatrix(); mat.SetPass(0); GL.LoadOrtho(); GL.Begin(GL.TRIANGLES); GL.Color(new Color(1, 1, 1, 1)); GL.Vertex3(0.5F, 0.25F, 0); GL.Vertex3(0.25F, 0.25F, 0); GL.Vertex3(0.375F, 0.5F, 0); GL.End(); GL.Begin(GL.QUADS); GL.Color(new Color(0.5F, 0.5F, 0.5F, 1)); GL.Vertex3(0.5F, 0.5F, 0); GL.Vertex3(0.5F, 0.75F, 0); GL.Vertex3(0.75F, 0.75F, 0); GL.Vertex3(0.75F, 0.5F, 0); GL.End(); GL.Begin(GL.LINES); GL.Color(new Color(0, 0, 0, 1)); GL.Vertex3(0, 0, 0); GL.Vertex3(0.75F, 0.75F, 0); GL.End(); GL.PopMatrix(); } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): public mat as Material def OnPostRender() as void: if not mat: Debug.LogError('Please Assign a material on the inspector') return GL.PushMatrix() mat.SetPass(0) GL.LoadOrtho() GL.Begin(GL.TRIANGLES) GL.Color(Color(1, 1, 1, 1)) GL.Vertex3(0.5F, 0.25F, 0) GL.Vertex3(0.25F, 0.25F, 0) GL.Vertex3(0.375F, 0.5F, 0) GL.End() GL.Begin(GL.QUADS) GL.Color(Color(0.5F, 0.5F, 0.5F, 1)) GL.Vertex3(0.5F, 0.5F, 0) GL.Vertex3(0.5F, 0.75F, 0) GL.Vertex3(0.75F, 0.75F, 0) GL.Vertex3(0.75F, 0.5F, 0) GL.End() GL.Begin(GL.LINES) GL.Color(Color(0, 0, 0, 1)) GL.Vertex3(0, 0, 0) GL.Vertex3(0.75F, 0.75F, 0) GL.End() GL.PopMatrix()