当前位置: 首页>>代码示例>>C#>>正文


C# VertexBuffer.Bind方法代码示例

本文整理汇总了C#中VertexBuffer.Bind方法的典型用法代码示例。如果您正苦于以下问题:C# VertexBuffer.Bind方法的具体用法?C# VertexBuffer.Bind怎么用?C# VertexBuffer.Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VertexBuffer的用法示例。


在下文中一共展示了VertexBuffer.Bind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FromBuffer

 public static VertexIndices FromBuffer(VertexBuffer indexBuffer, int count, DrawElementsType indexType)
 {
     return new VertexIndices((t) =>
     {
         indexBuffer.Bind(BufferTarget.ElementArrayBuffer, (b) =>
             GL.DrawElements(t, count, indexType, IntPtr.Zero));
     });
 }
开发者ID:kallisti-dev,项目名称:GameEngineConcept,代码行数:8,代码来源:VertexIndices.cs

示例2: CreateBuffer

        private IVertexBuffer CreateBuffer()
        {
            var result = new VertexBuffer<Vertex>(36, gl);
            
            // Set up every face omn the cube
            // Top
            result[0]  = new Vertex { Position = new Vector3f(-1, 1,  1), Normal = new Vector3f(0, 1, 0)};
            result[1]  = new Vertex { Position = new Vector3f( 1, 1,  1), Normal = new Vector3f(0, 1, 0) };
            result[2]  = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(0, 1, 0) };
            
            result[3]  = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(0, 1, 0) };
            result[4]  = new Vertex { Position = new Vector3f( 1, 1,  1), Normal = new Vector3f(0, 1, 0) };
            result[5]  = new Vertex { Position = new Vector3f( 1, 1, -1), Normal = new Vector3f(0, 1, 0) };

            // Bottom
            result[6]  = new Vertex { Position = new Vector3f(-1, -1,  1), Normal = new Vector3f(0,  -1, 0) };
            result[7] = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(0, -1, 0) };
            result[8]  = new Vertex { Position = new Vector3f( 1, -1,  1), Normal = new Vector3f(0,  -1, 0) };
            

            result[9]  = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(0, -1, 0) };
            result[10] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(0, -1, 0) };
            result[11] = new Vertex { Position = new Vector3f( 1, -1,  1), Normal = new Vector3f(0, -1, 0) };
            
            // Left
            result[12] = new Vertex { Position = new Vector3f(-1, 1, 1), Normal = new Vector3f(-1, 0, 0)};
            result[13] = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(-1, 0, 0) };
            result[14] = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(-1, 0, 0) };

            result[15] = new Vertex { Position = new Vector3f(-1, 1, 1), Normal = new Vector3f(-1, 0, 0) };
            result[16] = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(-1, 0, 0) };
            result[17] = new Vertex { Position = new Vector3f(-1, -1, 1), Normal = new Vector3f(-1, 0, 0) };

            // Right
            result[18] = new Vertex { Position = new Vector3f(1, 1, 1), Normal = new Vector3f(1, 0, 0) };
            result[19] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(1, 0, 0) };
            result[20] = new Vertex { Position = new Vector3f(1, 1, -1), Normal = new Vector3f(1, 0, 0) };

            result[21] = new Vertex { Position = new Vector3f(1, 1, 1), Normal = new Vector3f(1, 0, 0) };
            result[22] = new Vertex { Position = new Vector3f(1, -1, 1), Normal = new Vector3f(1, 0, 0) };
            result[23] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(1, 0, 0) };

            // Front
            result[24] = new Vertex {Position = new Vector3f(-1, 1, 1), Normal = new Vector3f(0, 0, 1)};
            result[25] = new Vertex { Position = new Vector3f(1, -1, 1), Normal = new Vector3f(0, 0, 1) };
            result[26] = new Vertex { Position = new Vector3f(1, 1, 1), Normal = new Vector3f(0, 0, 1) };

            result[27] = new Vertex { Position = new Vector3f(-1, 1, 1), Normal = new Vector3f(0, 0, 1) };
            result[29] = new Vertex { Position = new Vector3f(1, -1, 1), Normal = new Vector3f(0, 0, 1) };
            result[28] = new Vertex { Position = new Vector3f(-1, -1, 1), Normal = new Vector3f(0, 0, 1) };

            // Back
            result[30] = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(0, 0, -1) };
            result[32] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(0, 0, -1) };
            result[31] = new Vertex { Position = new Vector3f(1, 1, -1), Normal = new Vector3f(0, 0, -1) };

            result[33] = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(0, 0, -1) };
            result[34] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(0, 0, -1) };
            result[35] = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(0, 0, -1) };
            

            using (result.Bind())
            {
                result.BufferData(BufferUsage.StaticDraw);
            }

            return result;
        }
开发者ID:GeirGrusom,项目名称:ModGL,代码行数:68,代码来源:Cube.cs

示例3: Build

        public static Terrain Build(IOpenGL33 gl, int columns, int rows, float width, float depth)
        {
            var noise = new PerlinNoise();
            var noise2 = new PerlinNoise();
            
            var vertexBuffer = new VertexBuffer<PositionNormalTexCoord>((columns + 1) * (rows + 1), gl);
            var indexBuffer = new ElementBuffer<uint>(columns * rows * 6 , gl);

            float fx = - width / 2;
            float fy = -depth / 2;

            float dx = width / columns;
            float dy = depth / rows;

            int i = 0;

            for (int y = 0; y < (rows + 1); y++)
            {
                for (int x = 0; x < (columns + 1); x++, i++)
                {
                    float ix = fx + x * dx;
                    float iy = fy + y * dy;

                    const float detail = 0.25f;
                    const float detailScale = 0.2f;
                    const float macro = 0.008f;
                    const float macroScale = 4f;
                    var fUp = (float)((noise.Noise(x * detail, 0, (y + 1) * detail) - noise2.Noise(x * detail, 0, (y + 1) * detail) * 0.25f) * detailScale + noise.Noise(x * macro, 0, (y + 1) * macro) * macroScale) ;
                    var fDown = (float)((noise.Noise(x * detail, 0,  (y - 1) * detail) - noise2.Noise(x * detail, 0,  (y - 1) * detail) * 0.25f) * detailScale + noise.Noise(x * macro, 0,  (y - 1) * macro) * macroScale) ;
                    var fLeft = (float)((noise.Noise((x - 1) * detail, 0, y * detail) - noise2.Noise((x - 1) * detail, 0, y * detail) * 0.25f) * detailScale + noise.Noise((x - 1) * macro, 0, y * macro) * macroScale);
                    var fRight = (float)((noise.Noise((x + 1) * detail, 0, y * detail) - noise2.Noise((x + 1) * detail, 0, y * detail) * 0.25f) * detailScale + noise.Noise((x + 1) * macro, 0, y * macro) * macroScale);
                    var fThis = (float)((noise.Noise(x * detail, 0, y * detail) - noise2.Noise(x * detail, 0, y * detail) * 0.25f) * detailScale + noise.Noise(x * macro, 0, y * macro) * macroScale);

                    var vUp = new Vector3f(ix, fUp, iy - dy);
                    var vDown = new Vector3f(ix, fDown, iy + dy);
                    var vLeft = new Vector3f(ix - 1, fLeft, iy);
                    var vRight = new Vector3f(ix + 1, fRight, iy);
                    var vThis = new Vector3f(ix, fThis, iy);

                    var upperLeft = CalculateNormal(vLeft, vUp, vThis);
                    var upperRight = CalculateNormal(vUp, vRight, vThis);
                    var lowerRight = CalculateNormal(vRight, vDown, vThis);
                    var lowerLeft = CalculateNormal(vDown, vLeft, vThis);

                    var normal = upperLeft + upperRight + lowerLeft + lowerRight;
                    normal = new Vector3f(normal.X * 0.25f, normal.Y * 0.25f, normal.Z * 0.25f);

                    vertexBuffer[i] = new PositionNormalTexCoord { Normal = normal.Normalize(), Position = vThis, TexCoord = new Vector2f(vThis.X, vThis.Z)};
                }
            }
            int offset = 0;
            foreach(var index in Enumerable.Range(0, columns * rows + columns).Where(index => (index % (columns + 1)) != columns))
            {
                indexBuffer[offset] = (uint)index;
                indexBuffer[offset + 1] = (uint)(index + (columns + 1) + 1); 
                indexBuffer[offset + 2] = (uint)index + 1;

                indexBuffer[offset + 3] = (uint)index;                
                indexBuffer[offset + 4] = (uint)(index + (columns + 1));
                indexBuffer[offset + 5] = (uint)(index + (columns + 1) + 1);
                offset += 6;
            }

            using(vertexBuffer.Bind())
                vertexBuffer.BufferData(BufferUsage.StaticDraw);

            using(indexBuffer.Bind())
                indexBuffer.BufferData(BufferUsage.StaticDraw);

            var vertexArray = new VertexArray(gl, new[] {vertexBuffer}, new[] {PositionNormalTexCoord.Descriptor});

            var shader = new TerrainShader(gl);

            return new Terrain(gl, vertexArray, vertexBuffer, indexBuffer, shader);
        }
开发者ID:GeirGrusom,项目名称:ModGL,代码行数:75,代码来源:Terrain.cs

示例4: CreateVerticesForSquare

        /// <summary>
        /// Creates the geometry for the square, also creating the vertex buffer array.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        private void CreateVerticesForSquare(OpenGL gl)
        {
            var vertices = new float[18];
            var colors = new float[18]; // Colors for our vertices
            vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = 0.0f; // Bottom left corner
            colors[0] = 1.0f; colors[1] = 1.0f; colors[2] = 1.0f; // Bottom left corner
            vertices[3] = -0.5f; vertices[4] = 0.5f; vertices[5] = 0.0f; // Top left corner
            colors[3] = 1.0f; colors[4] = 0.0f; colors[5] = 0.0f; // Top left corner
            vertices[6] = 0.5f; vertices[7] = 0.5f; vertices[8] = 0.0f; // Top Right corner
            colors[6] = 0.0f; colors[7] = 1.0f; colors[8] = 0.0f; // Top Right corner
            vertices[9] = 0.5f; vertices[10] = -0.5f; vertices[11] = 0.0f; // Bottom right corner
            colors[9] = 0.0f; colors[10] = 0.0f; colors[11] = 1.0f; // Bottom right corner
            vertices[12] = -0.5f; vertices[13] = -0.5f; vertices[14] = 0.0f; // Bottom left corner
            colors[12] = 1.0f; colors[13] = 1.0f; colors[14] = 1.0f; // Bottom left corner
            vertices[15] = 0.5f; vertices[16] = 0.5f; vertices[17] = 0.0f; // Top Right corner
            colors[15] = 0.0f; colors[16] = 1.0f; colors[17] = 0.0f; // Top Right corner

            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();
            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, vertices, false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();
            colourDataBuffer.Create(gl);
            colourDataBuffer.Bind(gl);
            colourDataBuffer.SetData(gl, 1, colors, false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
        }
开发者ID:chantsunman,项目名称:sharpgl,代码行数:41,代码来源:Scene.cs


注:本文中的VertexBuffer.Bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。