【发布时间】:2016-04-14 10:37:35
【问题描述】:
我正在学习 OpenGL(使用 OpenTK)。今天我想使用 VBO 来有效地渲染我的四边形。 当我调用渲染时它崩溃了
=================================================================
Got a SIGSEGV while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.
=================================================================
Full stacktrace can be found here
这是我的渲染代码:
GL.EnableVertexAttribArray(0);
GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo);
GL.VertexAttribPointer(0, _count, VertexAttribPointerType.Float, false, 0, 0);
GL.DrawArrays(PrimitiveType.Quads, 0, _count);
GL.DisableVertexAttribArray(0);
这就是我生成缓冲区的方式。
GL.GenBuffers(1, out _vbo);
GL.BindBuffer( BufferTarget.ElementArrayBuffer, _vbo );
Vector3[] vertices;
_count = vertices.Length;
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer, new IntPtr(vertices.Length * Vector3.SizeInBytes), vertices, BufferUsageHint.StaticDraw);
PS:我没有为此使用任何颜色或纹理。
【问题讨论】:
-
我不确定,但您没有初始化数组“Vector3[] vertices;”。此外,您将缓冲区初始化为“BufferTarget.ElementArrayBuffer”,但将数据放入“BufferTarget.ArrayBuffer”中。以及您使用的是哪个版本的 OpenGL,因为由于一些更现代的版本您也必须使用顶点数组。
-
@Michael 顶点已定义(我从我的代码中将其从生成器所在的位置删除)。我尝试将 BufferTarget 更改为相同的值(对于两个值)但仍然无法正常工作。