用户工具

站点工具


侧边栏



Unity3D中文文档

script:unityengine:classes:gl:gl.loadpixelmatrix

GL.LoadPixelMatrix 加载像素矩阵

JavaScript ⇒ public static function LoadPixelMatrix(): void;
C# ⇒ public static void LoadPixelMatrix();

Description 描述

Setup a matrix for pixel-correct rendering.

设置一个矩阵用于像素矫正渲染。

This sets up modelview and projection matrices so that X, Y coordinates map directly to pixels. The (0,0) is at the bottom left corner of current camera's viewport. The Z coordinate goes from -1 to +1.

这设置模型视图和投影矩阵,为了使坐标X,Y映射为屏幕上的像素点。(0,0)对应视点的左下角。Z坐标值从-1到+1.

This function overrides current camera's parameters, so most often you want to save and restore matrices using GL.PushMatrix and GL.PopMatrix.

这个函数会覆盖当前camera的参数,许多情况下你需要用到GL.PushMatrix 和GL.PopMatrix矩阵函数来保存和恢复。

JavaScript:

	// Draws a red triangle using pixels as coordinates to paint on.
	var mat : Material;
 
	function OnPostRender() {
		if (!mat) {
			Debug.LogError("Please Assign a material on the inspector");
			return;
		}
		GL.PushMatrix();
		mat.SetPass(0);
		GL.LoadPixelMatrix();
		GL.Color(Color.red);
		GL.Begin(GL.TRIANGLES);
		GL.Vertex3(0,0,0);
		GL.Vertex3(0,Screen.height/2,0);
		GL.Vertex3(Screen.width/2,Screen.height/2,0);
		GL.End();
		GL.PopMatrix();
	}

C#:

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.LoadPixelMatrix();
        GL.Color(Color.red);
        GL.Begin(GL.TRIANGLES);
        GL.Vertex3(0, 0, 0);
        GL.Vertex3(0, Screen.height / 2, 0);
        GL.Vertex3(Screen.width / 2, Screen.height / 2, 0);
        GL.End();
        GL.PopMatrix();
    }
}

JavaScript ⇒ public static function LoadPixelMatrix(left: float, right: float, bottom: float, top: float): void;
C# ⇒ public static void LoadPixelMatrix(float left, float right, float bottom, float top);

Description 描述

Setup a matrix for pixel-correct rendering.

设置一个矩阵用于像素矫正渲染。

This sets up modelview and projection matrices so that X, Y coordinates map directly to pixels. The (left,bottom is at the bottom left corner of current camera's viewport; and (top,right) is at the top right corner of current camera's viewport. The Z coordinate goes from -1 to +1.

这设置模型视图和投影矩阵,为了使坐标X,Y映射为屏幕上的像素点。(left,bottom)在当前相机视图的左下角, (top,right)在当前相机视图的右上角,Z坐标值从-1到+1。

This function overrides current camera's parameters, so most often you want to save and restore matrices using GL.PushMatrix and GL.PopMatrix.

这个函数会覆盖当前camera的参数,许多情况下你需要用到GL.PushMatrix 和GL.PopMatrix矩阵函数来保存和恢复。

JavaScript:

	var mat : Material;
 
	function OnPostRender() {
		if (!mat) {
			Debug.LogError("Please Assign a material on the inspector");
			return;
		}
		GL.PushMatrix();
		mat.SetPass(0);
		GL.LoadPixelMatrix(10,20,10,20);
		GL.Color(Color.red);
		GL.Begin(GL.TRIANGLES);
		GL.Vertex3(10,10,0);
		GL.Vertex3(10,20,0);
		GL.Vertex3(20,20,0);
		GL.End();
		GL.PopMatrix();
	}

C#:

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.LoadPixelMatrix(10, 20, 10, 20);
        GL.Color(Color.red);
        GL.Begin(GL.TRIANGLES);
        GL.Vertex3(10, 10, 0);
        GL.Vertex3(10, 20, 0);
        GL.Vertex3(20, 20, 0);
        GL.End();
        GL.PopMatrix();
    }
}

GL

script/unityengine/classes/gl/gl.loadpixelmatrix.txt · 最后更改: 2016/08/02 05:24 (外部编辑)