PDA

View Full Version : Something wrong with Vertex Buffer Object!



HanWu
12-04-2008, 06:45 PM
I tried to render objects with the Vertex buffer object and it works but the problem is when I use glBegin() and glEnd to draw a line, the line doens't show out. I am using c# and Tao as my opengl wrapper. The code snippet is as follow:

internal virtual void BindVertexBuffer(int verterCount, int[] m_nVBOVertices, double[] m_pVertices)
{
// generate the buffer
Gl.glGenBuffersARB(1, m_nVBOVertices);
Console.WriteLine("VBO" + m_nVBOVertices[0].ToString());
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, m_nVBOVertices[0]);

// initialize this buffer. we dont have data yet tho
Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB, (IntPtr)(verterCount * 3 * sizeof(double)), m_pVertices, Gl.GL_STATIC_DRAW_ARB);
}

public void Draw()
{
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, mesh.m_nVBOVertices[0]); //vPosition

Gl.glVertexPointer(3, Gl.GL_DOUBLE, 0, (IntPtr)0);
Gl.glDrawArrays(Gl.GL_QUADS, 0, mesh.bilVertex);
Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
}

Any help will be appreciated. Thanks !

tamlin
12-04-2008, 07:24 PM
That code isn't using Begin/End at all. Add some (liberally sprinkled) glGetError calls too.

Sidenote: Don't use double's - use float. You'll likely experience a quite measurable performance gain.

++luck;

HanWu
12-04-2008, 08:16 PM
I have solved the problem. Anyway thanks for the reply.