【问题标题】:OpenTK - VBO - Application crashOpenTK - VBO - 应用程序崩溃
【发布时间】: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 更改为相同的值(对于两个值)但仍然无法正常工作。

标签: c# opengl vbo opentk


【解决方案1】:

将渲染代码更改为此

        GL.BindBuffer( BufferTarget.ArrayBuffer, _vbo );
        GL.VertexPointer (3, VertexPointerType.Float, Marshal.SizeOf(new Vector3()), IntPtr.Zero);
        GL.EnableClientState (ArrayCap.VertexArray);

        GL.DrawArrays(PrimitiveType.Quads, 0, _count);

        GL.DisableClientState (ArrayCap.VertexArray);

它奏效了。 我在任何地方都使用了 BufferTarget.ArrayBuffer(ElementArrayBuffer 用于索引)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多