예제 #1
0
        public PointRenderer(OpenGL gl, IStaticScene scene)
        {
            _gl    = gl;
            _scene = scene;

            _program = new ShaderBindable(gl, "Shaders/Point.vert", "Shaders/Point.frag");
            _vao     = new VAO(gl);
            _vbo     = new VBO(gl);

            using (Bind.These(_vao, _vbo))
            {
                count = scene.Points.Count;

                _vbo.Update(scene.Points.Select(p => new Vertex(p.Position, p.Color)));

                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, Vertex.Stride, new IntPtr(0));

                gl.EnableVertexAttribArray(1);
                gl.VertexAttribPointer(1, 4, OpenGL.GL_FLOAT, false, Vertex.Stride, new IntPtr(sizeof(float) * 3));
            }
        }
예제 #2
0
        public PostProcesser(OpenGL gl, int width, int height)
        {
            _gl  = gl;
            _fbo = new FBO(gl, width, height);

            _flatProgram = new ShaderBindable(gl, "Shaders/Flat.vert", "Shaders/Flat.frag");



            _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);
                }
            _start = DateTime.Now;
        }
예제 #3
0
        public BackgroundRenderer(OpenGL gl, IBackground background)
        {
            _gl      = gl;
            _program = new ShaderBindable(gl, "Shaders/Background.vert", "Shaders/Background.frag");

            _vao = new VAO(gl);
            var flatBuffer = new VBO(gl);

            using (new Bind(_vao))
                using (new Bind(flatBuffer))
                {
                    var data = new List <float>();
                    data.AddRange(new float[] { -1, -1 });
                    data.AddRange(background.BottomLeft.ToFloatArray());
                    data.AddRange(new float[] { 1, -1 });
                    data.AddRange(background.BottomRight.ToFloatArray());
                    data.AddRange(new float[] { 1, 1 });
                    data.AddRange(background.TopRight.ToFloatArray());
                    data.AddRange(new float[] { -1, 1 });
                    data.AddRange(background.TopLeft.ToFloatArray());

                    var flatData = data.ToArray();

                    flatBuffer.Update(flatData, flatData.Length * sizeof(float));

                    const int stride = sizeof(float) * 6;

                    gl.EnableVertexAttribArray(0);
                    gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, stride, new IntPtr(0));

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

                    gl.BindVertexArray(0);
                }
        }