Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

GL.LoadPixelMatrix

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public static function LoadPixelMatrix(): void;
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.

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

	// 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(); }
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(); } }

public static function LoadPixelMatrix(left: float, right: float, bottom: float, top: float): void;
public static void LoadPixelMatrix(float left, float right, float bottom, float top);

Parameters

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.

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

	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(); }
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(); } }