Example #1
0
 public static void Init()
 {
     if(vbo==null){
          VertexPositionColor[] CubeVertices = new VertexPositionColor[]
     {
         new VertexPositionColor( 0.0f, 0.0f,  1.0f, Color.HotPink),
         new VertexPositionColor( 1.0f, 0.0f,  1.0f, Color.HotPink),
         new VertexPositionColor( 1.0f,  1.0f,  1.0f, Color.HotPink),
         new VertexPositionColor( 0.0f,  1.0f,  1.0f, Color.HotPink),
         new VertexPositionColor( 0.0f, 0.0f, 0.0f, Color.HotPink),
         new VertexPositionColor( 1.0f, 0.0f, 0.0f, Color.HotPink),
         new VertexPositionColor( 1.0f,  1.0f, 0.0f, Color.HotPink),
         new VertexPositionColor( 0.0f,  1.0f, 0.0f, Color.HotPink)
     };
         short[] CubeElements = new short[]
         {
             0, 1, 2, 2, 3, 0, // front face
             3, 2, 6, 6, 7, 3, // top face
             7, 6, 5, 5, 4, 7, // back face
             4, 0, 3, 3, 7, 4, // left face
             0, 1, 5, 5, 4, 0, // bottom face
             1, 5, 6, 6, 2, 1, // right face
         };
         vbo= new VertexBufferObject(CubeVertices, CubeElements);
     }
 }
        public VertexBufferObject(VertexPositionColor[] verts, short[] elements)
        {
            //TODO error on misallovated buffers
            vertstride =BlittableValueType.StrideOf(verts);
            //bind our vertexes

            GL.GenBuffers(1,out this.VboId);
            GL.BindBuffer (BufferTarget.ArrayBuffer, this.VboId);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Length * vertstride), verts, BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out vbobuffersize);

            //bind our indexes
            GL.GenBuffers(1, out this.EboId);
            GL.BindBuffer (BufferTarget.ElementArrayBuffer, this.EboId);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(elements.Length * BlittableValueType.StrideOf(elements)), elements, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer,BufferParameterName.BufferSize, out ebobuffersize);

            this.ElementSize   = elements.Length;
        }