GL 图像库

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类变量

  • Mode for  Begin: draw triangles.
    Begin模式开始后,然后绘制三角形。
  • Mode for  Begin: draw triangle strip.
    Begin模式开始后,然后绘制三角形带。
  • Mode for  Begin: draw quads.
    Begin模式开始后,然后绘制四边形。
  • Mode for  Begin: draw lines.
    Begin模式开始后,然后绘制线。
  • The current modelview matrix.
    返回目前的模型视图矩阵。

Class Functions类函数

  • Submit a vertex.
    绘制一个顶点。
  • Submit a vertex.
    绘制一个顶点。
  • Sets current vertex color.
    设置目前顶点颜色。
  • Sets current texture coordinate (v.x,v.y,v.z) for all texture units.
    设置当前纹理(v.x,v.y,v.z)坐标用于所有的纹理单元。
  • Sets current texture coordinate (x,y) for all texture units.
    设置纹理(x,y)坐标对于所有的纹理单元。
  • Sets current texture coordinate (x,y,z) for all texture units.
    设置纹理(x,y,z)坐标对于所有的纹理单元。
  • Sets current texture coordinate (x,y) for the actual texture unit.
    设置纹理(x,y,)坐标对于当前的纹理单元。(多重纹理)
  • Sets current texture coordinate (x,y,z) to the actual texture unit.
    设置纹理(x,y,z)坐标对于当前的纹理单元(多重纹理)。
  • Sets current texture coordinate (v.x,v.y,v.z) to the actual texture unit.
    设置纹理(x,y,z)坐标对于当前的纹理单元(多重纹理)。
  • Begin drawing 3D primitives.
    开始绘制3d原始物体。
  • End
    End drawing 3D primitives.
    结束绘制3D原始物体。
  • Helper function to set up an ortho perspective transform.
    辅助函数用来做一个正交投影变换。
  • Setup a matrix for pixel-correct rendering.
    设置一个矩阵用于像素矫正渲染。
  • Set the rendering viewport.
    定义渲染的视口。
  • Load an arbitrary matrix to the current projection matrix.
    加载一个任意的矩阵到当前的投影矩阵。
  • Load the identity matrix to the current modelview matrix.
    加载一个单位矩阵到当前的模型视图矩阵。
  • Multiplies the current modelview matrix with the one specified.
    用当前的模型视图矩阵乘以矩阵。
  • Saves both projection and modelview matrices to the matrix stack.
    把投影视图矩阵和模型视图矩阵压入堆栈保存。
  • Restores both projection and modelview matrices off the top of the matrix stack.
    把投影视图矩阵和模型视图矩阵弹出堆栈。
  • Compute GPU projection matrix from camera's projection matrix.
    从Camera的投影矩阵得到GPU(图形处理器)的投影矩阵。
  • Select whether to invert the backface culling (true) or not (false).
    是否关闭背面消隐功能。默认情况下,背面消隐功能是打开的。
  • Clear the current render buffer.
    清除当前的缓冲区。
  • Clear the current render buffer with camera's skybox.
    用camera的天空盒清空缓冲区。
  • Invalidate the internally cached renderstates.
    使内部渲染绘制状态无效。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值