Пример #1
0
        public BasicShaderProgram(CameraUBO ubo)
        {
            CompileShader(ShaderType.VertexShader, @"#version 400
            precision highp float;

            layout(std140) uniform Camera {
            mat4 MVP;
            mat4 Model;
            mat4 View;
            mat4 Projection;
            mat4 NormalMatrix;
            };
            layout (location = 0) in vec3 vert_position;
            layout (location = 1) in vec3 vert_normal;
            layout (location = 2) in vec4 vert_colour;
            out vec4 col;

            void main(void)
            {
            gl_Position = (MVP) * vec4(vert_position, 1);
            col = vert_colour;
            }");
            CompileShader(ShaderType.FragmentShader, @"#version 400
            in vec4 col;
            layout( location = 0 ) out vec4 FragColor;
            void main() {
            FragColor = col;
            }");
            Link();
            ubo.BindToShaderProgram(this);
        }
Пример #2
0
        protected override void OnLoad(EventArgs e)
        {
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            //solid = new Cube();
            var data = new List<OpenGLVertex>
            {
                new OpenGLVertex {Position = new Vector3(-1, -1, 0), Colour  =new Color4(0.118f, 0.118f, 0.118f, 1f).ToVector4()},//bottom left
                new OpenGLVertex {Position = new Vector3(1, -1, 0), Colour= new Color4(0.118f, 0.118f, 0.118f, 1f).ToVector4() }, //bottom right
                new OpenGLVertex {Position = new Vector3(1, 1, 0), Colour = new Color4(0.176f, 0.176f, 0.188f, 1f).ToVector4() },//top right
                new OpenGLVertex {Position = new Vector3(-1, 1, 0), Colour =  new Color4(0.176f, 0.176f, 0.188f, 1f).ToVector4()},//top left
            };

            _ubo = new CameraUBO();

            _shader = new FlatShaderProgram();
            _basicShader = new BasicShaderProgram(_ubo);

            _vbo = new VBO(data) { BeginMode = BeginMode.Quads };
            _vao = new VAO(_shader, _vbo);

            var dotdata = new List<OpenGLVertex>
            {
                new OpenGLVertex {Position = new Vector3(0, 0, 0)},
                new OpenGLVertex {Position = new Vector3(10, 10, 0)},
            };

            _dotsvbo = new VBO(dotdata) { BeginMode = BeginMode.Lines };
            _dotsvao = new VAO(_basicShader, _dotsvbo);

            var stl = new STL("rounded_cube.stl", Color.GreenYellow);

            var cubedata = new List<OpenGLVertex>();
            var col = stl.Color.ToVector4();

            foreach (var ele in stl.Elements)
            {
                cubedata.Add(new OpenGLVertex { Position = ele.P1.ToVector3(), Normal = ele.Normal.ToVector3(), Colour = col });
                cubedata.Add(new OpenGLVertex { Position = ele.P2.ToVector3(), Normal = ele.Normal.ToVector3(), Colour = col });
                cubedata.Add(new OpenGLVertex { Position = ele.P3.ToVector3(), Normal = ele.Normal.ToVector3(), Colour = col });
            }

            _geovbo = new VBO(cubedata) { BeginMode = BeginMode.Triangles };
            _geovao = new VAO(_basicShader, _geovbo);

            var err = GL.GetError();
            if (err != ErrorCode.NoError)
                Console.WriteLine("Error at OnLoad: " + err);
        }
Пример #3
0
        protected override void OnLoad(EventArgs e)
        {
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.PointSize(5f);

            _ubo = new CameraUBO();
            _shader = new BasicShaderProgram(_ubo);

            _vao = new VAO(_shader, new VBO(new List<Vertex>(FetchData(_tree))) { BeginMode = BeginMode.Quads });

            var green = new Color4(0.156f, 0.627f, 0.353f, 1.0f).ToVector4();
            var data = new List<Vertex>();

            foreach (var element in stl.Elements)
            {
                data.Add(new Vertex { Colour = green, Position = element.P1.ToVector3() });
                data.Add(new Vertex { Colour = green, Position = element.P2.ToVector3() });
                data.Add(new Vertex { Colour = green, Position = element.P3.ToVector3() });
            }

            _vao2 = new VAO(_shader, new VBO(data) { BeginMode = BeginMode.Triangles });

            var filled = _tree.Flatten().Where(o => o.State == NodeState.Filled).ToArray();

            _vaoFilled = new VAO(_shader, new VBO(new List<Vertex>(FetchDataSolid(filled))) { BeginMode = BeginMode.Quads });

            var err = GL.GetError();
            if (err != ErrorCode.NoError)
                Console.WriteLine("Error at OnLoad: " + err);
        }