OpenGL ES: Vertex/Color Buffers/Pointers
I have a large volume of points I'm reading from a file that have both 3D positions and RGB values. I'm struggling to render these via Java+Android+OpenGL(ES).
I create a vertex buffer, and color buffer:
private FloatBuffer vertexBuffer, colorBuffer;
Pin my vertices to the buffer:
ByteBuffer vbb = ByteBuffer.allocateDirect(lasVertices.length * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(lasVertices);
vertexBuffer.position(0);
And in my draw (GL10 gl):
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glColorPointer(3, GL10.GL_FLOAT, 0, co开发者_JAVA百科lorBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glPointSize(3);
gl.glDrawArrays(GL10.GL_POINTS, 0, 100);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
Which does draw a small sample of 100 points on the screen, but without color. I've pinned the color into the colorBuffer
I created above while running code, as such:
lasColors[i*3] = array[i].red;
lasColors[i*3+1] = array[i].green;
lasColors[i*3+2] = array[i].blue;
But How can I render the unique values in step with the positions of the vertices?
I tried what I did with the positions:
vbb = ByteBuffer.allocateDirect(lasColors.length * 4);
vbb.order(ByteOrder.nativeOrder());
colorBuffer = vbb.asFloatBuffer();
colorBuffer.put(lasColors);
colorBuffer.position(0);
and showing this into my draw function:
gl.glColorPointer(3, GL10.GL_FLOAT, 0, colorBuffer);
...but didn't get any results.
Try enabling the color array along with the vertex array and see if that works.
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(3, GL10.GL_FLOAT, 0, colorBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glPointSize(3);
gl.glDrawArrays(GL10.GL_POINTS, 0, 100);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
精彩评论