本文整理汇总了C#中VertexBuffer.Create方法的典型用法代码示例。如果您正苦于以下问题:C# VertexBuffer.Create方法的具体用法?C# VertexBuffer.Create怎么用?C# VertexBuffer.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VertexBuffer
的用法示例。
在下文中一共展示了VertexBuffer.Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}