yuriks's picture

VBO problems: nothing gets drawn

Hey. I'm having some issues using VBOs. This is the code I have right now:

        public void Draw(Point position)
        {
            int[] vertexData = {
                                                     position.X, position.Y,
                                                     position.X + Image.Width, position.Y,
                                                     position.X, position.Y + Image.Height,
                                                     position.X + Image.Width, position.Y + Image.Height
                                               };
 
            uint glVertexBuffer;
 
            GL.GenBuffers(1, out glVertexBuffer);
            GL.BindBuffer(BufferTarget.ArrayBuffer, glVertexBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertexData.Length * sizeof(int)), vertexData, BufferUsageHint.StreamDraw);
 
            int size; // This is 32, like it should be so I assumed the buffer got uploaded correctly.
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferMapped, out size);
 
            GL.EnableClientState(EnableCap.VertexArray);
 
            GL.BindBuffer(BufferTarget.ArrayBuffer, glVertexBuffer);
            GL.VertexPointer(2, VertexPointerType.Int, 0, 0);
 
            //GL.BindTexture(TextureTarget.Texture2D, glTexture);
            GL.Disable(EnableCap.Texture2D);
 
            GL.Color3(1.0f, 1.0f, 1.0f);
 
            GL.BindBuffer(BufferTarget.ArrayBuffer, glVertexBuffer);
            GL.DrawArrays(BeginMode.TriangleStrip, 0, vertexData.Length);
 
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.DisableClientState(EnableCap.VertexArray);
 
            GL.DeleteBuffers(1, ref glVertexBuffer);
 
            /*GL.Begin(BeginMode.TriangleStrip);
            GL.TexCoord2(0, 0);
            GL.Vertex2(position.X, position.Y);
 
            GL.TexCoord2(1, 0);
            GL.Vertex2(position.X + Image.Width, position.Y);
 
            GL.TexCoord2(0, 1);
            GL.Vertex2(position.X, position.Y + Image.Height);
 
            GL.TexCoord2(1, 1);
            GL.Vertex2(position.X + Image.Width, position.Y + Image.Height);
            GL.End();*/
        }

I call SwapBuffer later on in another function. The commented out immediate mode section is what I want to replace, and that works fine, but using VBOs, nothing get's drawn. I've checked using GL.GetError after every function call and no errors are reported. Anyone got a clue on what I'm doing wrong?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Actually, this has been tried before: Tao 1.3 universally replaced void* with array types (float[], float[,], float[,,], byte[], byte[,], ...), IIRC ~20 overloads for each void* (bloated), when only five or six were valid at any time (incorrect). And what if you actually needed a float[][]? (inflexible)

Sometimes the simplest solution is the best one.

What we could do is detect 0 and replace it with IntPtr.Zero (adding overhead). Or we could document that you should use IntPtr.Zero instead of 0.

Right now, I'm leaning towards the latter - but I'm always open to ideas.

Just to clarify this, the following ideas are impossible:

  1. We cannot detect the correct overloads automatically (no such info in the specs).
  2. We cannot add the correct overloads by hand (too many, too error prone).
objarni's picture

I can see the (practical) problem of "X number of overloads", yes. So I rest my case :)