Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用VBO/IBOs绘制大型图形_C#_Opengl_Vbo_Opentk - Fatal编程技术网

C# 用VBO/IBOs绘制大型图形

C# 用VBO/IBOs绘制大型图形,c#,opengl,vbo,opentk,C#,Opengl,Vbo,Opentk,我正在尝试使用OpenTK绘制一个大型图(~3000000个顶点,~5000000条边) 然而,我似乎无法让它工作 我创建了一个包含所有顶点位置的VBO,如下所示 // build the coords list float[] coords = new float[vertices.Length * 3]; Dictionary<int, int> vertexIndexMap = new Dictioanry<int, int>(); int count = 0, i

我正在尝试使用OpenTK绘制一个大型图(~3000000个顶点,~5000000条边)

然而,我似乎无法让它工作

我创建了一个包含所有顶点位置的VBO,如下所示

// build the coords list
float[] coords = new float[vertices.Length * 3];
Dictionary<int, int> vertexIndexMap = new Dictioanry<int, int>();
int count = 0, i = 0;
foreach (Vertex v in vertices) {
    vertexIndexMap[v.Id] = i++;
    coords[count++] = v.x;
    coords[count++] = v.y;
    coords[count++] = v.z;
}

// build the index list
int[] indices = new int[edges.Length * 2];
count = 0;
foreach (Edge e in edges) {
    indices[count++] = vertexIndexMap[e.First.Id];
    indices[count++] = vertexIndexMap[e.Second.Id];
}

// bind the buffers
int[] bufferPtrs = new int[2];
GL.GenBuffers(2, bufferPtrs);

GL.EnableClientState(ArrayCap.VertexArray);
GL.EnableClientState(ArrayCap.IndexArray);

// buffer the vertex data
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferPtrs[0]);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(coords.Length * sizeof(float)), coords, BufferUsageHint.StaticDraw);
GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero); // tell opengl we have a closely packed vertex array
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

// buffer the index data
GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferPtrs[1]);
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(int)), indices, BufferUsageHint.StaticDraw);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
当我运行此操作时,所有顶点都会按预期在其所有正确位置绘制,
但是,将顶点连接到原点绘制了大约一半的边

为了检查是否正常,我试着用开始/结束块绘制边缘,它们都画得正确


有人能指出我是如何误用VBOs的吗?

您的
drawerelements()
调用的最后一个参数是错误的:

GL.DrawElements(PrimitiveType.Lines, indices.Length, DrawElementsType.UnsignedInt,
                bufferPtrs[1]);
如果没有元素数组缓冲区bund,
draurements()
的最后一个参数是指向索引的指针。如果绑定了元素数组缓冲区(代码中就是这种情况),则最后一个参数是缓冲区中的偏移量。要使用整个缓冲区,偏移量为0:

GL.DrawElements(PrimitiveType.Lines, indices.Length, DrawElementsType.UnsignedInt, 0);
您可能还想删除此呼叫:

GL.EnableClientState(ArrayCap.IndexArray);

这不是用于启用顶点索引,而是用于颜色索引。这将用于颜色索引模式,这是一个非常过时的功能。

调用
drawerelements()
的最后一个参数是错误的:

GL.DrawElements(PrimitiveType.Lines, indices.Length, DrawElementsType.UnsignedInt,
                bufferPtrs[1]);
如果没有元素数组缓冲区bund,
draurements()
的最后一个参数是指向索引的指针。如果绑定了元素数组缓冲区(代码中就是这种情况),则最后一个参数是缓冲区中的偏移量。要使用整个缓冲区,偏移量为0:

GL.DrawElements(PrimitiveType.Lines, indices.Length, DrawElementsType.UnsignedInt, 0);
您可能还想删除此呼叫:

GL.EnableClientState(ArrayCap.IndexArray);

这不是用于启用顶点索引,而是用于颜色索引。这将用于颜色索引模式,这是一个非常过时的功能。

调用
drawerelements()
的最后一个参数是错误的:

GL.DrawElements(PrimitiveType.Lines, indices.Length, DrawElementsType.UnsignedInt,
                bufferPtrs[1]);
如果没有元素数组缓冲区bund,
draurements()
的最后一个参数是指向索引的指针。如果绑定了元素数组缓冲区(代码中就是这种情况),则最后一个参数是缓冲区中的偏移量。要使用整个缓冲区,偏移量为0:

GL.DrawElements(PrimitiveType.Lines, indices.Length, DrawElementsType.UnsignedInt, 0);
您可能还想删除此呼叫:

GL.EnableClientState(ArrayCap.IndexArray);

这不是用于启用顶点索引,而是用于颜色索引。这将用于颜色索引模式,这是一个非常过时的功能。

调用
drawerelements()
的最后一个参数是错误的:

GL.DrawElements(PrimitiveType.Lines, indices.Length, DrawElementsType.UnsignedInt,
                bufferPtrs[1]);
如果没有元素数组缓冲区bund,
draurements()
的最后一个参数是指向索引的指针。如果绑定了元素数组缓冲区(代码中就是这种情况),则最后一个参数是缓冲区中的偏移量。要使用整个缓冲区,偏移量为0:

GL.DrawElements(PrimitiveType.Lines, indices.Length, DrawElementsType.UnsignedInt, 0);
您可能还想删除此呼叫:

GL.EnableClientState(ArrayCap.IndexArray);

这不是用于启用顶点索引,而是用于颜色索引。这将适用于颜色索引模式,这是一个非常过时的功能。

哇,这就是所有的错误。我在文件里没看到!谢谢你。谢谢你指出关于IndexArray的事。哇,这就是所有的错误。我在文件里没看到!谢谢你。谢谢你指出关于IndexArray的事。哇,这就是所有的错误。我在文件里没看到!谢谢你。谢谢你指出关于IndexArray的事。哇,这就是所有的错误。我在文件里没看到!谢谢你。谢谢你指出关于IndexArray的问题。