-1

I am learning OpenGL (using OpenTK). Today I want to use VBO to render my quads effectively. When I call render it crash

=================================================================
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

This is my render code:

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);

And this is how I generate buffers.

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: I am not using any colors or textures for this.

  • I am not sure but you are not init the Array "Vector3[] vertices;". Further more you init your buffer as "BufferTarget.ElementArrayBuffer" but put data in with "BufferTarget.ArrayBuffer". And which Version of OpenGL you are using, because since some more modern Versions you have to use Vertex Arrays, too. – Michael Apr 15 '16 at 20:46
  • @Michael vertices are defined (I cut it out of my code where is generator). I tried to change BufferTarget to same values (for both values) but still not working. – AbitDeveloper Apr 16 '16 at 14:31

1 Answers1

0

Changed render code to this

        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);

and it worked. I used BufferTarget.ArrayBuffer everywhere (ElementArrayBuffer is for indices).