using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class ShowGrid : MonoBehaviour {
public int lineCount = ;
public float radius = 4f; static Material lineMaterial; public void OnRenderObject()
{
CreateLineMaterial();
// Apply the line material
lineMaterial.SetPass(); GL.PushMatrix();
// Set transformation matrix for drawing to
// match our transform
GL.MultMatrix(transform.localToWorldMatrix); // Draw lines
GL.Begin(GL.LINES);
for (int i = ; i < lineCount; ++i)
{
float a = i / (float)lineCount;
float angle = a * Mathf.PI * ;
// Vertex colors change from red to green
GL.Color(new Color(a, - a, , 0.8F));
// One vertex at transform position
GL.Vertex3(, , );
// Another vertex at edge of circle
GL.Vertex3(Mathf.Cos(angle) * radius, Mathf.Sin(angle) * radius, );
}
GL.End();
GL.PopMatrix();
} void OnPostRender()
{
// Set your materials
GL.PushMatrix();
// yourMaterial.SetPass( );
// Draw your stuff
GL.PopMatrix(); } static void CreateLineMaterial()
{
if (!lineMaterial)
{
// Unity has a built-in shader that is useful for drawing
// simple colored things.
Shader shader = Shader.Find("Hidden/Internal-Colored");
lineMaterial = new Material(shader);
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
// Turn on alpha blending
lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
// Turn backface culling off
lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
// Turn off depth writes
lineMaterial.SetInt("_ZWrite", );
}
} }

Unity使用OpenGL绘制线段的更多相关文章

  1. Unity使用OpenGL绘制经纬线圈

    using System.Collections; using System.Collections.Generic; using UnityEngine; public class LatLonGr ...

  2. Opengl绘制我们的小屋(二)第一人称漫游

    这章我们先讲第一人称漫游的实现.在openTK里,我们用函数Matrix4.LookAt(caram.Eye,caram.Target,Vector3.UnitY)来放置摄像机,其中三个参数分别与摄像 ...

  3. [Modern OpenGL系列(三)]用OpenGL绘制一个三角形

    本文已同步发表在CSDN:http://blog.csdn.net/wenxin2011/article/details/51347008 在上一篇文章中已经介绍了OpenGL窗口的创建.本文接着说如 ...

  4. Quartz2D复习(一)--- 基础知识 / 绘制线段圆弧 / 图片水印 / 截图

    1.Quartz 2D是一个二维绘图引擎,同时支持ios和Mac系统: Quart2D的API是纯C语言的,API来自于Core  Graphics框架: 2.Quartz 2D可以绘制图形(线段/三 ...

  5. opengl绘制正弦曲线

    利用opengl绘制正弦曲线 ,见代码: #include <windows.h> //#include <GLUT/glut.h> #include <GL/glut. ...

  6. OpenGL绘制自由落体小球

    OpenGL绘制自由落体小球 一.    程序运行的软硬件环境 本次设计在window10系统下进行,运用C++进行编写,在CodeBlocks环境下使用OpenGL进行设计. 所需环境配置分为2部分 ...

  7. OpenGL绘制简单场景,实现旋转缩放平移和灯光效果

    本项目实现了用OpenGL绘制一个简单场景,包括正方体.球体和网格,实现了物体的旋转.缩放.平移和灯光效果.附有项目完整代码.有具体凝视.适合刚開始学习的人熟悉opengl使用. 开发情况 开发环境V ...

  8. C#GDI+ 绘制线段(实线或虚线)、矩形、字符串、圆、椭圆

    C#GDI+ 绘制线段(实线或虚线).矩形.字符串.圆.椭圆 绘制基本线条和图形 比较简单,直接看代码. Graphics graphics = e.Graphics; //绘制实线 )) { pen ...

  9. OpenGl 绘制一个立方体

    OpenGl 绘制一个立方体 为了绘制六个正方形,我们为每个正方形指定四个顶点,最终我们需要指定6*4=24个顶点.但是我们知道,一个立方体其实总共只有八个顶点,要指定24次,就意味着每个顶点其实重复 ...

随机推荐

  1. Windows 7 incorrectly reports "No Internet Access"

    PROBLEM DESCRIPTION Windows 7 may sometimes report that it has "No Internet Access"; this ...

  2. cat more less 命令

    查看文件内容的几种常用的方法   1 在Linux系统中有三种命令可以用来查阅全部的文件,分别是cat.more和less命令.它们查阅文件的使用方法也比较简单都是 命令 文件名 ,但是三者又有着区别 ...

  3. 自然语言交流系统 phxnet团队 创新实训 项目博客 (十三)

    对我们项目中的关键技术实现进行总结: 一.3DMax关键技术实现 1.一下的关于3DMax中对于人物的设计和操作均需要在对3DMax基础知识熟练掌握的情况下进行的. 2. 骨骼架设:首先对导入到3DM ...

  4. 自然语言交流系统 phxnet团队 创新实训 项目博客 (七)

    在本项目中使用到的“语音转文本”的技术总结: 语音转文本部分是调用的科大讯飞的在线语音,它的激发方式是按键,通过按钮触发开启安卓设备的录音,此部分需要在源码中写入关于安卓权限的要求,来调用安卓的录音权 ...

  5. 《FPGA全程进阶---实战演练》第十一章 VGA五彩缤纷

    1基础理论部分 VGA(video graphics array)即视频图形阵列,是IBM在1987年随PS/2一起推出的使用模拟信号的一种视频传输标准.VGA相比与现在的视频传输接口来说已经过时,不 ...

  6. qualcomm lk gpio

    关于高通平台lk中控制gpio的记录 http://blog.csdn.net/loongembedded/article/details/72834761 http://blog.csdn.net/ ...

  7. Spring Data Commons 官方文档学习

    Spring Data Commons 官方文档学习   -by LarryZeal Version 1.12.6.Release, 2017-07-27 为知笔记版本在这里,带格式. Table o ...

  8. JUnit4 基本用法实例

    本教程介绍了在JUnit4中支持的基本注解. import org.junit.*; import static org.junit.Assert.*; import java.util.*; /** ...

  9. 推荐个office能在线预览的插件

    1.chrome  office viewer 这个可以离线使用 2.微软 office web app  可以使用微软在线服务器或则自己搭建服务器 有兴趣的朋友百度一下具体操作方法

  10. ssh命令详解3

    SSH 的详细使用方法如下: ssh [-l login_name] [hostname | user@hostname] [command] ssh [-afgknqtvxCPX246] [-c b ...