Exemplo n.º 1
0
        void CreateVertexBuffer3()
        {
            var vertexAttribute = RendererHelper.attributeVertexPositionColor <float, float>();

            VertexPositionColor <float, float>[] vertices =
            {
                new VertexPositionColor <float, float>(new Vec3 <float>(0.0f,  -0.5f, 0.0f), new Color <float>(1.0f, 0.0f, 0.0f, 1.0f)),
                new VertexPositionColor <float, float>(new Vec3 <float>(-0.5f,  0.5f, 0.0f), new Color <float>(0.0f, 1.0f, 0.0f, 1.0f)),
                new VertexPositionColor <float, float>(new Vec3 <float>(0.0f,   0.5f, 0.0f), new Color <float>(0.0f, 0.0f, 1.0f, 1.0f))
            };

            int[] indices =
            {
                0, 1, 2
            };

            vb3 = graphics.CreateVertexBufferIndexed(vertices, indices, BufferUsage.StaticDraw, vertexAttribute.Value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a indexed vertex buffer by using a vec3 array
        /// </summary>
        void CreateVertexBuffer2()
        {
            // Either create the attribute manually or use the built-in function
            //var vertexAttribute = new VertexAttribute(3, DataType.Single, 3 * sizeof(float), 0);
            var vertexAttribute = RendererHelper.attributeVertexPositionTexture <float, float>();

            /// When you have only positions you can either use the pos array directly or use the vertices array
            Vec3 <float>[] pos =
            {
                new Vec3 <float>(0.0f, -0.5f, 0.0f),
                new Vec3 <float>(0.5f, -0.5f, 0.0f),
                new Vec3 <float>(0.5f,  0.5f, 0.0f),
                new Vec3 <float>(0.0f,  0.5f, 0.0f)
            };

            Vec2 <float>[] tex =
            {
                new Vec2 <float>(0.0f, 1.0f),
                new Vec2 <float>(1.0f, 1.0f),
                new Vec2 <float>(1.0f, 0.0f),
                new Vec2 <float>(0.0f, 0.0f)
            };

            VertexPosTex <float, float>[] vertices =
            {
                new VertexPosTex <float, float>(pos[0], tex[0]),
                new VertexPosTex <float, float>(pos[1], tex[1]),
                new VertexPosTex <float, float>(pos[2], tex[2]),
                new VertexPosTex <float, float>(pos[3], tex[3])
            };

            uint[] indices =
            {
                0, 1, 2,
                0, 2, 3
            };

            // create vertex buffer object with vertex data, an attribute and indices
            vb2 = graphics.CreateVertexBufferIndexed(vertices, indices, BufferUsage.StaticDraw, vertexAttribute.Value);
        }