语言English
  • C#

GL.Begin

声明

public static void Begin(int mode);

参数

mode 要绘制的图元:可以是 TRIANGLESTRIANGLE_STRIPQUADSLINES

描述

开始绘制 3D 图元。

在 OpenGL 中,这与 glBegin 相匹配;在其他图形 API 中,会模拟相同的功能。在 GL.Begin 和 GL.End 之间,可以调用 GL.VertexGL.ColorGL.TexCoord 和其他立即模式绘制函数。

在自行绘制图元时,应注意剔除。剔除规则可能因游戏运行的图形 API 而异。在大多数情况下,最安全的方法是在着色器中使用 Cull Off 命令。

其他资源:GL.End

using UnityEngine;

public class Example : MonoBehaviour { // Draws a Triangle, a Quad and a line // with different colors

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); // Triangle GL.Color(new Color(1, 1, 1, 1)); GL.Vertex3(0.50f, 0.25f, 0); GL.Vertex3(0.25f, 0.25f, 0); GL.Vertex3(0.375f, 0.5f, 0); GL.End();

GL.Begin(GL.QUADS); // Quad 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); // Line GL.Color(new Color(0, 0, 0, 1)); GL.Vertex3(0, 0, 0); GL.Vertex3(0.75f, 0.75f, 0); GL.End(); GL.PopMatrix(); } }

Did you find this page useful? Please give it a rating: