Reputation: 5949
I'm trying to draw a gradient, but first I just want to get the glcolorpointer working. If I use glColor4f(...) it draw colors correctly, but the glcolorpointer just draws black. Help please
gl11.glPushMatrix();
//gl11.glColor4f(RGBBorder[0], RGBBorder[1], RGBBorder[2], alpha);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexPointerCube);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexPointerCube);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
float colors[] = {.7f,.7f,.7f,.5f};
ByteBuffer vbb = ByteBuffer.allocateDirect(colors.length * 4);
vbb.order(ByteOrder.nativeOrder());
FloatBuffer buff = vbb.asFloatBuffer();
buff.put(colors);
buff.position(0);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, buff);
gl11.glVertexPointer(3, GL10.GL_FLOAT, 0, 0);
gl11.glDrawElements(GL11.GL_TRIANGLES, indicesCube, GL11.GL_UNSIGNED_SHORT, 0);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
gl11.glPopMatrix();
Upvotes: 2
Views: 2186
Reputation: 6073
I think the problem is that you add color for one vertex only, and leave buff
too small to handle all vertices you have. Using color buffer you're supposed to have, in this case, 4 floats per vertex, times 8 (assuming it's a cube you're drawing). It should be very much the same as introducing your vertex coordinates, even though I've never played around with GL11.glBindBuffer
. This time with the difference it's a color value you're assigning for each vertex.
This tutorial is very good read if you haven't done it already.
Upvotes: 5