Exemplo n.º 1
0
        protected override void OnLoad()
        {
            GL.ClearColor(1f, 1f, 1f, 1.0f);

            VertexBufferObject = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
            GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);

            VertexArrayObject = GL.GenVertexArray();
            GL.BindVertexArray(VertexArrayObject);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexArrayObject);
            GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);

            ElementBufferObject = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
            GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.StaticDraw);

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
            GL.EnableVertexAttribArray(0);

            Shader = new Shader(
                Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"shaders\shader.vert.glsl")),
                Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"shaders\shader.frag.glsl")));

            Shader.Use();

            _timer = new Stopwatch();
            _timer.Start();

            base.OnLoad();
        }
Exemplo n.º 2
0
 private static void overrideDataInAttributeList(int ID, int attrib, int coordSize, float[] data)
 {
     GL.BindBuffer(BufferTarget.ArrayBuffer, ID);
     GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.DynamicDraw);
     GL.VertexAttribPointer(attrib, coordSize, VertexAttribPointerType.Float, false, 0, 0);
     GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
 }
Exemplo n.º 3
0
        public static void LoadIndexer(int shaderProgramHandle, uint [] indicesVboData)
        {
            int indicesVboHandle;

            GL.GenBuffers(1, out indicesVboHandle);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indicesVboHandle);
            GL.BufferData(BufferTarget.ElementArrayBuffer,
                          new IntPtr(indicesVboData.Length * sizeof(uint)),
                          indicesVboData, BufferUsageHint.StaticDraw);
        }
Exemplo n.º 4
0
        protected override void OnUnload()
        {
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindVertexArray(0);
            GL.UseProgram(0);

            // Delete all the resources.
            GL.DeleteBuffer(VertexBufferObject);
            GL.DeleteVertexArray(VertexArrayObject);

            GL.DeleteProgram(Shader.Handle);
            base.OnUnload();
        }
Exemplo n.º 5
0
        private static int storeDataInAttributeList(int attrib, int coordSize, float[] data)
        {
            int vboID = GL.GenBuffer();

            VBOs.Add(vboID);

            GL.BindBuffer(BufferTarget.ArrayBuffer, vboID);
            GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.DynamicDraw);
            GL.VertexAttribPointer(attrib, coordSize, VertexAttribPointerType.Float, false, 0, 0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            return(vboID);
        }
Exemplo n.º 6
0
        public static void LoadVertexPositions(int shaderProgramHandle, Vector3[] positionVboData)
        {
            int positionVboHandle;

            GL.GenBuffers(1, out positionVboHandle);
            GL.BindBuffer(BufferTarget.ArrayBuffer, positionVboHandle);
            GL.BufferData <Vector3>(BufferTarget.ArrayBuffer,
                                    new IntPtr(positionVboData.Length * Vector3.SizeInBytes),
                                    positionVboData, BufferUsageHint.StaticDraw);


            GL.EnableVertexAttribArray(0);
            GL.BindAttribLocation(shaderProgramHandle, 0, "inPosition");
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes, 0);
        }
Exemplo n.º 7
0
 public void BindBuffer(GLBufferTarget target, GLBufferHandle buffer)
 {
     GL.BindBuffer((BufferTarget)target, (int)buffer);
 }