Unity GL 绘制图形

来源:互联网 发布:linux文件权限为400 编辑:程序博客网 时间:2024/04/29 16:10




using UnityEngine;using System.Collections;public class Script_07_17 : MonoBehaviour {//可用材质public Material mat0;public Material mat1;public Material mat3;void OnPostRender() {//绘制正四边方形DrawRect(100,100,100,100,mat0);DrawRect(250,100,100,100,mat1);//绘制无规则四边形DrawQuads(15,5,10,115,95,110,90,10,mat3);}/** 绘制正四边形 float x :X轴起始坐标 float y :Y轴起始坐标  float width :正四边形的宽 float height :正四边形的高  */void DrawRect(float x,float y,float width,float height,Material mat){GL.PushMatrix();mat.SetPass(0);GL.LoadOrtho();//绘制类型为四边形GL.Begin(GL.QUADS);GL.Vertex3(x/Screen.width, y/Screen.height, 0);GL.Vertex3(x/Screen.width, (y + height)/Screen.height, 0);GL.Vertex3((x+ width)/Screen.width, (y + height)/Screen.height, 0);GL.Vertex3((x+ width)/Screen.width,y/Screen.height, 0);GL.End();GL.PopMatrix();}/** 绘制无规则四边形 float x1 :起始点1,X1坐标 float y1 :起始点1,Y1坐标 float x2 :起始点2,X2坐标 float y2 :起始点2,X2坐标  float x3 :起始点3,X3坐标 float y3 :起始点3,X3坐标  float x4 :起始点4,X4坐标 float y4 :起始点4,X4坐标*/void DrawQuads(float x1,float y1,float x2,float y2,float x3,float y3,float x4, float y4,Material mat){GL.PushMatrix();mat.SetPass(0);GL.LoadOrtho();//绘制类型为四边形GL.Begin(GL.QUADS);GL.Vertex3(x1/Screen.width, y1/Screen.height, 0);GL.Vertex3(x2/Screen.width, y2/Screen.height, 0);GL.Vertex3(x3/Screen.width, y3/Screen.height, 0);GL.Vertex3(x4/Screen.width, y4/Screen.height, 0);GL.End();GL.PopMatrix();}}


原创粉丝点击