
GL.GenBuffers gives zero
Posted Wednesday, 19 December, 2012 - 16:20 by rtbo inHello
I can't get VBOs to work on my machine. GL.GenBuffers always give me zero.
I use in this way:
(I unfortunately have to use VB !)
<StructLayout(LayoutKind.Sequential)> _ Public Structure Vertex Dim C As Color4 Dim N As Vector3 Dim P As Vector3 End Structure Protected vBuf_ As Integer Protected iBuf_ As Integer Public Sub RegisterVBO() GL.GenBuffers(1, vBuf_) GL.GenBuffers(1, iBuf_) 'MsgBox(GL.GetError()) 'MsgBox(vBuf_) 'MsgBox(iBuf_) End Sub
GL.GetError() here above returns zero as well
Therefore, the following drawing code doesn't work, I guess the above is the cause:
Public Sub BufferVideo() GL.BindBuffer(BufferTarget.ArrayBuffer, vBuf_) GL.BufferData(BufferTarget.ArrayBuffer, CType((vertices_.Length * 10 * 4), IntPtr), _ vertices_, BufferUsageHint.StaticDraw) GL.BindBuffer(BufferTarget.ElementArrayBuffer, iBuf_) GL.BufferData(BufferTarget.ElementArrayBuffer, CType(indices_.Length * 2, IntPtr), _ indices_, BufferUsageHint.StaticDraw) End Sub Private Sub VBO() GL.EnableClientState(ArrayCap.ColorArray) GL.EnableClientState(ArrayCap.NormalArray) GL.EnableClientState(ArrayCap.VertexArray) GL.BindBuffer(BufferTarget.ArrayBuffer, vBuf_) GL.BindBuffer(BufferTarget.ElementArrayBuffer, iBuf_) GL.ColorPointer(4, ColorPointerType.Float, 10 * 4, CType(0, IntPtr)) GL.NormalPointer(NormalPointerType.Float, 10 * 4, CType(4 * 4, IntPtr)) GL.VertexPointer(3, VertexPointerType.Float, 10 * 4, CType(7 * 4, IntPtr)) GL.DrawElements(BeginMode.Triangles, indices_.Length, DrawElementsType.UnsignedShort, 0) GL.DrawArrays(BeginMode.Triangles, 0, vertices_.Length) GL.EnableClientState(ArrayCap.ColorArray) GL.EnableClientState(ArrayCap.NormalArray) GL.EnableClientState(ArrayCap.VertexArray) End Sub
Note that replacing the VBO code above with the following immediate code works OK. it shows my model on screen
Private Sub Immediate() GL.Begin(BeginMode.Triangles) For Each i As UShort In indices_ Dim v As Vertex = vertices_(i) GL.Color4(v.C) GL.Vertex3(v.P) GL.Normal3(v.N) Next GL.End() End Sub
Do I do something wrong?
Is there a problem with the OpenGL driver (I haven't tested on any other machine yet) ?
(I don't know how to get info about my driver by the way)
Thanks for your help


Comments
Re: GL.GenBuffers gives zero
I solved my problem.
The RegisterVBO() sub was called from the rendering thread, before I called Context.MakeCurrent()
Re: GL.GenBuffers gives zero
I solved my problem.
The RegisterVBO() function was called in the OpenGL thread before I called Context.MakeCurrent()