Beispiel #1
0
        public BackgroundRenderer(OpenGL gl)
        {
            _gl = gl;

            _program = new BackgroundShader(gl);
            _flat = new VAO(gl);
            _flatBuffer = new VBO(gl);

            using (new Bind(_flat))
            using (new Bind(_flatBuffer))
            {
                var flatData = new float[] { -1, -1, 1, -1, -1, 1, 1, 1, };
                _flatBuffer.Update(flatData, flatData.Length * sizeof(float));
                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
                gl.BindVertexArray(0);
            }
        }
Beispiel #2
0
        public PostProcesser(OpenGL gl,int width,int height)
        {
            _gl = gl;
            _fbo = new FBO(gl, width, height);

            _flatProgram = new FlatShader(gl);

            _flat = new VAO(gl);
            _flatBuffer = new VBO(gl);

            using (new Bind(_flat))
            using (new Bind(_flatBuffer))
            {
                var flatData = new float[] { -1, -1, 1, -1, -1, 1, 1, 1, };
                _flatBuffer.Update(flatData, flatData.Length * sizeof(float));
                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
                gl.BindVertexArray(0);
            }
        }
Beispiel #3
0
        public OctreeRenderer(OctreeModel model, OpenGL gl)
        {
            _gl = gl;
            _octreeProgram = new OctreeShader(gl);
            _cubes = new VAO(gl);
            _cubeBuffer = new VBO(gl);

            var filled = model.Node.Flatten().Where(o => o.State == NodeState.Filled).ToArray();
            _count = filled.Length;
            var list = new List<float>();
            foreach (var octreeNode in filled)
            {
                list.AddRange(octreeNode.Center.ToArray().Select(d => (float)d));

                list.AddRange(new[]
                        {
                            (float)MathsHelper.Map(octreeNode.Color.R, 0, 255, 0, 1),
                            (float)MathsHelper.Map(octreeNode.Color.G, 0, 255, 0, 1),
                            (float)MathsHelper.Map(octreeNode.Color.B, 0, 255, 0, 1),
                            (float)MathsHelper.Map(octreeNode.Color.A, 0, 255, 0, 1),
                            (float)octreeNode.Size
                        });
            }

            var vertices = list.ToArray();

            using (new Bind(_cubes))
            using (new Bind(_cubeBuffer))
            {
                _cubeBuffer.Update(vertices, vertices.Length * sizeof(float));
                const int stride = sizeof(float) * 8;
                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, stride, new IntPtr(0));

                gl.EnableVertexAttribArray(1);
                gl.VertexAttribPointer(1, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 3));

                gl.EnableVertexAttribArray(2);

                gl.VertexAttribPointer(2, 1, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 7));
                gl.BindVertexArray(0);
            }
        }