GL 图像库

Low-level graphics library.

底层的图像库。

Use this class to manipulate active transformation matrices, issue rendering commands similar to OpenGL's immediate mode and do other low-level graphics tasks. Note that in almost all cases using Graphics.DrawMesh is more efficient than using immediate mode drawing.

这个类进行底层的矩阵变换。通过用函数命令来实现。这和OpenGL(和D3D不同的图形库)的立即模式一样。注意在大部分情况下用Graphics.DrawMesh 比这个立即模式更有效率。

GL immediate drawing functions use whatever is the "current material" set up right now. The material controls how the rendering is done (blending, textures, etc.), so unless you explicitly set it to something before using GL draw functions, the material can happen to be anything. Also, if you call any other drawing commands from inside GL drawing code, they can set material to something else, so make sure it's under control as well.

GL的立即模式用在当材质建立的时候。材质控制着物体该如何渲染(混合纹理等等)。在用GL类前你要明确的设定材质的属性,GL类可以使材质做任何改变。  (下面的实例代码看看会清楚一点)

GL drawing commands execute immediately. That means if you call them in Update(), they will be executed before the camera is rendered (and the camera will most likely clear the screen, making the GL drawing not visible).

GL函数命令会立即执行。不要在Update()函数内放置GL代码,这样会看不到效果。因为GL在 Camera 之前被执行。

The usual place to call GL drawing is most often in OnPostRender() from a script attached to a camera

常用的方法是GL代码放在OnPostRender()函数里面。OnPostRender()作为camera 脚本里的一个函数。

static var lineMaterial : Material;

static function CreateLineMaterial() {
	if( !lineMaterial ) {
		lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
			"SubShader { Pass { " +
			" Blend SrcAlpha OneMinusSrcAlpha " +
			" ZWrite Off Cull Off Fog { Mode Off } " +
			" BindChannels {" +
			" Bind \"vertex\", vertex Bind \"color\", color }" +
			"} } }" );
		lineMaterial.hideFlags = HideFlags.HideAndDontSave;
		lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
	}
}

function OnPostRender() {
	CreateLineMaterial();
	// set the current material
	//设置当前的材质
	lineMaterial.SetPass( 0 );
	GL.Begin( GL.LINES );
	GL.Color( Color(1,1,1,0.5) );
	GL.Vertex3( 0, 0, 0 );
	GL.Vertex3( 1, 0, 0 );
	GL.Vertex3( 0, 1, 0 );
	GL.Vertex3( 1, 1, 0 );
	GL.Color( Color(0,0,0,0.5) );
	GL.Vertex3( 0, 0, 0 );
	GL.Vertex3( 0, 1, 0 );
	GL.Vertex3( 1, 0, 0 );
	GL.Vertex3( 1, 1, 0 );
	GL.End();
} 

Note: This class is almost used when you need to draw a couple of lines or triangles, and don't want to deal with meshes. If you want to avoid surprises the usage pattern is this:

注意:这个类使用于当你需要绘制几条线或三角形,并不想使用网格。如果你想避免意外使用模式是这样的:

function OnPostRender() {
	// Set your materials
	//设置材质
	GL.PushMatrix();
	// yourMaterial.SetPass( );
	// Draw your stuff
	//绘制你的东西
	GL.PopMatrix();
}

where at the "// Draw your stuff" you should do SetPass() on some material previously declared, which will be used for drawing. If you dont call SetPass, then you'll get basically a random material (whatever was used before) which is not good. So do it.

在// Draw your stuff注释位置,你可以做 SetPass(),之前声明的一些材质,将永远绘制。如果你不调用SetPass,那么你将获得基本上是一个随机材质(不管是使用之前)这是不好的,因此要做这步。

This class is only available in Unity Pro.
这个类只能在Unity Pro专业版可用。

IMPORTANT: This class has no effect on iPhone.

重要事项:这个类在iphone上没有效果。

Class Variables类变量

Class Functions类函数

最后修改:2011年8月5日 Friday 21:43

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。