elaverick's picture

OutOfMemory when trying to use a colour buffer

I'm trying to add a colour buffer to a program that already successfully uses a VBO however when I try and draw with the new colour buffer I get an OutOfMemory error from OpenGL.

Here's my Colour Buffer:

private Vector4[] colourBuffer = new Vector4[]{
            new Vector4(1.0f,0.0f,0.0f,1.0f),
            new Vector4(1.0f,0.1f,0.0f,1.0f),
            new Vector4(1.0f,0.2f,0.0f,1.0f),
            new Vector4(1.0f,0.3f,0.0f,1.0f),
            new Vector4(1.0f,0.4f,0.0f,1.0f),
            new Vector4(1.0f,0.5f,0.0f,1.0f),
            new Vector4(1.0f,0.6f,0.0f,1.0f),
            new Vector4(1.0f,0.7f,0.0f,1.0f),
            new Vector4(1.0f,0.8f,0.0f,1.0f),
            new Vector4(1.0f,0.9f,0.0f,1.0f),
            new Vector4(1.0f,1.0f,0.0f,1.0f)
        };

Here's my VBO setup code:

private void createVBO(ref int vboID, ref int colourID)
        {
            GL.EnableClientState(ArrayCap.VertexArray);                     // Enable VBOs
            GL.EnableClientState(ArrayCap.ColorArray);
 
            GL.GenBuffers(1, out vboID);                                    // Generate our buffer
            GL.BindBuffer(BufferTarget.ArrayBuffer, vboID);                 // Bind the buffer to the ID
            GL.VertexPointer(3, VertexPointerType.Float, 0, (IntPtr)0);     // Define the vertex array
 
            GL.GenBuffers(1, out colourID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, colourID);
            GL.ColorPointer(4, ColorPointerType.Float, 0, (IntPtr)0);
        }

And here's the buffer drawing code:

private void drawVBO(Vector3[] points)
        {
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(12 * points.Length), IntPtr.Zero, BufferUsageHint.StreamDraw); // Clear the old buffer
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(12 * points.Length), points, BufferUsageHint.StreamDraw); // Upload the new buffer
            GL.BufferData<Vector4>(BufferTarget.ArrayBuffer, (IntPtr)(colourBuffer.Length * Vector4.SizeInBytes), colourBuffer, BufferUsageHint.StreamDraw);
            GL.DrawArrays(BeginMode.LineStrip, 0, points.Length); // Draw the Array in LineStrip mode
            MessageBox.Show(GL.GetError().ToString());
        }

What am I doing wrong?


Comments

Comment viewing options

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

I'm an idiot I forgot to switch back to the vertex buffer for rendering...