- Begin
- ClearWithSkybox
- Clear
- Color
- End
- InvalidateState
- LINES
- LoadIdentity
- LoadOrtho
- LoadPixelMatrix
- LoadProjectionMatrix
- modelview
- MultiTexCoord2
- MultiTexCoord3
- MultiTexCoord
- MultMatrix
- PopMatrix
- PushMatrix
- QUADS
- SetRevertBackfacing
- TexCoord2
- TexCoord3
- TexCoord
- TRIANGLE_STRIP
- TRIANGLES
- Vertex3
- Vertex
- Viewport
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类变量
-
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 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.
使内部渲染绘制状态无效。