Color- and texture-anomalities when using Vertex Buffers.

Hi list,

I’m having trouble adding color and texture-coordinates to my vertices in a Vertex Buffer. I use this to fill my colorbuffer and put them into a Vertex Buffer (like I do for the vertices and indices) :


colorbuffer = BufferUtils.createFloatBuffer(4 * 4);
colorbuffer.put(255).put(0).put(0).put(255);
colorbuffer.put(255).put(0).put(0).put(255);
colorbuffer.put(255).put(0).put(0).put(255);
colorbuffer.put(255).put(0).put(0).put(255);
colorbuffer.flip();

ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_COLOR_ARRAY_BUFFER_BINDING_ARB, colorbufferID);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_COLOR_ARRAY_BUFFER_BINDING_ARB, colorbuffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);

This gives the following compile error:
“Unsupported VBO target 34970”

I’m pretty sure I know what this means, but what kind of buffer should I use then? Perhaps I’m doing something terribly wrong?

If I use the GL_ARRAY_BUFFER_ARB flag, everything seems to work:


ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, colorbufferID);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, colorbuffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);

…but then I’m overwriting my vertex buffer ofcourse.
How can I avoid this please? What is the correct way to use this?

Thank you!

You’re not overriding your vertex data this way (or at least: shouldn’t be)

it’s like this:


bindBuffer(..., x)
bufferData(..., dataX, ...)

bindBuffer(..., y)
bufferData(..., dataY, ...)

now buffer x holds dataX
now buffer y holds dataY

According to your topic-title, you see artifacts.

This happens when your VBO has less elements than required.
like if vertex-array has 12 elements and color-array has 9 elements… the last 3 elements will be garbage colors

One problem I see with this is that you are specifying your color buffer as a FloatBuffer, but specifying your colors as 255,0,0,255 (red, presumably). The valid range of a float color component is [0…1]. Try using 1.0f instead of 255. It may look ok because the values are being clamped to the proper range for you.

At any rate, the GL_ARRAY_BUFFER_ARB usage you mentioned secondly is the correct usage, not GL_COLOR_ARRAY_BUFFER_BINDING_ARB. Why do you think this is incorrect? (Maybe I’m misuing my VBOs but I use G_ARRAY_BUFFER_ARB to create & load my vbos with data).

Thank you, that was indeed my problem (stupid mistake, if you think about it :)). Everything works like a charm now.

I guess I was a bit confused with the “glEnableClientState()”-method where they explicitly use different states, like “GL11.GL_TEXTURE_COORD_ARRAY” and “GL11.GL_COLOR_ARRAY”.

Thanks again for the help!