zoukankan      html  css  js  c++  java
  • Unity GL

    画线:

    DrawLine.cs 脚本挂到一个新的 GameObject 上

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    /// <summary>
    /// 屏幕坐标画线
    /// </summary>
    public class DrawLine : MonoBehaviour {
    
        private static Material s_lineMaterial;
    
        private static void CreateLineMaterial () {
            // 如果材质球不存在
            if (!s_lineMaterial) {
                // 用代码的方式实例一个材质球
                Shader shader = Shader.Find("Hidden/Internal-Colored");
                s_lineMaterial = new Material(shader);
                s_lineMaterial.hideFlags = HideFlags.HideAndDontSave;
                // 设置参数
                s_lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                s_lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                // 设置参数
                s_lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
                // 设置参数
                s_lineMaterial.SetInt("_ZWrite", 0);
            }
        }
    
        private void OnRenderObject () {
            // 创建材质球
            CreateLineMaterial();
    
            // 激活第一个着色器 Pass(本例中,它是唯一的 Pass)
            s_lineMaterial.SetPass(0);
    
            // 渲染入栈  在Push——Pop之间写GL代码
            GL.PushMatrix();
            {
                // 1.用屏幕坐标绘图,移动对象时图像保持不动
                GL.LoadPixelMatrix();
                
                // 2.使用局部坐标绘图,移动对象时图像也会移动
                // 矩阵相乘,将物体坐标转化为世界坐标
                //GL.MultMatrix(transform.localToWorldMatrix);
    			
    			// 1,2 都不使用时,使用世界坐标绘图,移动对象时图像保持不动
    
                // 开始画线  在Begin——End之间写画线方式
                // GL.LINES 画线
                GL.Begin(GL.LINES);
                {
                    GL.Color(Color.green);
                    GL.Vertex3(0, 0, 0);
                    GL.Vertex3(500, 500, 0);
                }
                GL.End();
            }
            // 渲染出栈
            GL.PopMatrix();
    
        }
    
    }
    
  • 相关阅读:
    利用存储过程生成随机数,并用其它存储过程调用此过程
    dataGridView中的数据操作
    listView绑定数据
    我的简易 数据存取器 的封装
    dataGridView 控件的简单绑定
    文件写入写出的封装
    Button1.Attributes.Add()方法小结
    自定义分页栏
    安迪的找工作日志——9.12笔试(优酷土豆)问题及解答
    安迪的找工作日志——9.13在教四四楼墙上看到的
  • 原文地址:https://www.cnblogs.com/kingBook/p/15136434.html
Copyright © 2011-2022 走看看