GL example 1

using UnityEngine;
using System.Collections;

public class joint
{
    public Vector3 org;
    public Vector3 end;
}

public class example : MonoBehaviour
{
    Event e;
    private Vector3 orgPos;
    private Vector3 endPos;
    private bool canDrawLines = false;
    ArrayList posAL;
    ArrayList temppos;
    public Material lineMaterial;

    void Start ()
    {
        temppos = new ArrayList ();
        posAL = new  ArrayList ();
    }

    void Update ()
    {
        if (Input.GetMouseButton (0)) {
            canDrawLines = true;
        }
        if (e.type != null & canDrawLines) {
            if (e.type == EventType.MouseDown) {
                orgPos = Input.mousePosition;
                endPos = Input.mousePosition;  

            }
            if (e.type == EventType.MouseDrag) {
                endPos = Input.mousePosition;
                //鼠标位置信息存入数组
                temppos.Add (Input.mousePosition);
                GLDrawLine (orgPos, endPos);
                orgPos = Input.mousePosition;
                print (temppos.Count);
            }
            if (e.type == EventType.MouseUp) {
                // orgPos=Input.mousePosition;
                endPos = Input.mousePosition;
            }
        }  

    }

    void GLDrawLine (Vector3 beg, Vector3 end)
    {
        if (!canDrawLines)
            return;
        GL.PushMatrix ();
        GL.LoadOrtho ();  

        beg.x = beg.x / Screen.width;
        end.x = end.x / Screen.width;
        beg.y = beg.y / Screen.height;
        end.y = end.y / Screen.height;
        joint tmpJoint = new joint ();
        tmpJoint.org = beg;
        tmpJoint.end = end;  

        posAL.Add (tmpJoint);  

        lineMaterial.SetPass (0);
        GL.Begin (GL.LINES);
        GL.Color (new Color (1, 1, 1, 0.5f));
        for (int i= 0; i<posAL.Count; i++) {
            joint tj = (joint)posAL [i];
            Vector3 tmpBeg = tj.org;
            Vector3 tmpEnd = tj.end;
            GL.Vertex3 (tmpBeg.x, tmpBeg.y, tmpBeg.z);
            GL.Vertex3 (tmpEnd.x, tmpEnd.y, tmpEnd.z);
        }
        GL.End ();
        GL.PopMatrix ();
    }

    void OnGUI ()
    {
        e = Event.current;  

        if (GUI.Button (new  Rect (150, 0, 100, 50), "End Lines")) {
            ClearLines ();
        }
    }

    void ClearLines ()
    {
        canDrawLines = false;
        posAL.Clear ();
    }

    void OnPostRender ()
    {
        GLDrawLine (orgPos, endPos);
    }
}
时间: 2024-08-06 03:39:26

GL example 1的相关文章

unity3d GL画线/物体跟随/坐标系转换

看见标题的人是不是在想... 一个小小的GL画线难吗? 一个小小的物体跟随难吗? 嗯,的确,一点不难.... 我一开始也是像你们那样想的,但是实际操作起来,还是和理论有区别的 写这个demo起因是这样的: 面试到了一家虚拟现实的公司,因为没有去公司 网上直接谈的,谈妥了hr估计是想看看我能不能胜任 给了我一张效果图,让我去实现画线的功能 咳咳,要求还是比较细致的,这里我们后面说 废话不多说,老规矩,先上效果图,然后直接进入主题 第一张是hr给我的图,第二张是我自己实现的 需求如下: 1.模型是旋

glew, glee与 gl glu glut glx glext的区别

GLEW是一个跨平台的C++扩展库,基于OpenGL图形接口.使用OpenGL的朋友都知道,window目前只支持OpenGL1.1的涵数,但 OpenGL现在都发展到2.0以上了,要使用这些OpenGL的高级特性,就必须下载最新的扩展,另外,不同的显卡公司,也会发布一些只有自家显卡才支 持的扩展函数,你要想用这数涵数,不得不去寻找最新的glext.h,有了GLEW扩展库,你就再也不用为找不到函数的接口而烦恼,因为GLEW能自动识 别你的平台所支持的全部OpenGL高级扩展涵数.也就是说,只要包

&quot;https://open.gl/&quot;教程之Drawing Polygons源码(freeglut版)

VERTEX_SHADER #version 150 core in vec2 position; in vec3 color; out vec3 Color; void main(){ Color=color; gl_Position=vec4(position.x,-position.y,0,1); } FRAGMENT_SHADER #version 150 core out vec4 outColor; in vec3 Color; uniform vec3 triangleColor;

&quot;https://open.gl/&quot;教程之Textures源码(freeglut版)

VERTEX_SHADER: #version 150 core in vec2 position; in vec3 color; in vec2 texcoord; out vec3 Color; out vec2 TexCoord; void main(){ Color=color; TexCoord=texcoord; gl_Position=vec4(position,0,1); } FRAGMENT_SHADER: #version 150 core in vec3 Color; in

IOS逆向分析——GL脚本的提取

总结:要逆一个程序必须清楚地知道程序的结构和常用的API函数,不清楚一个程序而去逆出结果是不可能滴 首先是glsl脚本运行的全过程,第一步是为shader的运行创建一个容器GLuint glCreateProgram(void),第二步是把编译好的shader附加到程序void glAttachShader(GLuint program, GLuint shader),编译好的shader可以是多个所以第二步可以重复多步把每一个编译好的一一附加到程序,顶点shader和像素shader一一成对,

OpenGL2.0及以上版本中gl,glut,glew,glfw,mesa等部件的关系

OpenGL2.0及以上版本中gl,glut,glew,glfw,mesa等部件的关系 一.OpenGL OpenGL函数库相关的API有核心库(gl),实用库(glu),辅助库(aux).实用工具库(glut),窗口库(glx.agl.wgl)和扩展函数库等. gl是核心,glu是对gl的部分封装.glx.agl.wgl 是针对不同窗口系统的函数.glut是为跨平台的OpenGL程序的工具包,比aux功能强大(aux很大程度上已经被glut库取代.).扩展函数库是硬件厂商为实现硬件更新利用Op

用GL画出人物的移动路径

注意:用Debug画的线会存在穿透问题 没啥好解释的,直接看代码: using UnityEngine; using System.Collections; using System.Collections.Generic; /* * 找不到设置线宽的方法,目前的解决方法就是用画矩形代替画线来实现线的粗细 */ /// <summary> /// 必须将此脚本放在摄影机上才能看到绘画内容,DebugDraw可以不用,但DebugDraw画的内容 /// 只能在编辑模式下看得到. /// <

OpenGL的gl.h出现一堆错误,如重定义什么的

问题:生成时提示 gl.h中出现一堆错误,如 error C2144: 语法错误 : "void"的前面应有";" error C2182: "APIENTRY" : 非法使用"void"类型 error C2086: "int APIENTRY" : 重定义 error C2146: 语法错误 : 缺少";"(在标识符"glClearStencil"的前面) 解决办

gl.h报错

以下内容摘自:http://blog.csdn.net/kaphen/article/details/24721999 头文件只有#include <gl\gl.h> //OpenGL Header #include <gl\glu.h> //GLu32 Header 时候出现以下错误 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\gl.h(1152): error C2144: 语法错

Qt编译错误GL/gl.h: No such file or directory

最近把系统换成ubuntu14.04的了,在安装Qt后,我运行了里面的一个示例,发现编译有错: 其实我以前就遇到过这个问题,我当时给我的朋友写了一封邮件,他告诉我说是因为系统中没有安装OpenGL库导致的,所以我们要安装OpenGL库及其工具: 这个是他当时给我回的邮件,我发现我现在的系统中没有最后一个软件,可能是因为新系统换了比较新的软件源的关系吧.我的做法是运行这个命令 [email protected]:~$ sudo apt-get install freeglut3-dev 之后就可以