Android OpenGL Point Clouds

I'm trying to use

gl.glDrawElements(GL10.GL_POINTS, 4, GL10.GL_UNSIGNED_BYTE, vertexBuffer);

draw 4 points on my screen using vertex buffer, but I can't get it to work. All I want to do is glasses, because in the end I want to make a display of point clouds. If I have a large number of points (after all), is this a vertex buffer, a way to go? They will not change, but I want to change the perspective and scale at which they are viewed.

vertexBuffer setup:

private float vertices[] = {
    -3.0f,  1.0f, -2.0f,  // 0, Top Left
    -3.0f, -1.0f, 0.0f,  // 1, Bottom Left
    -2.0f, -1.0f, -2.0f,  // 2, Bottom Right
    -2.0f,  1.0f, 0.0f,  // 3, Top Right
    };


// Our vertex buffer.
private FloatBuffer vertexBuffer;
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);

This is my current call to call for my points (I do not want indexes, because the order of drawing the figure does not matter to me):

public void draw(GL10 gl) {
    // Enabled the vertices buffer for writing and to be used during 
    // rendering.
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPointSize(3);

    // Specifies the location and data format of an array of vertex
    // coordinates to use when rendering.
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);

    gl.glDrawElements(GL10.GL_POINTS, 4, 
             GL10.GL_UNSIGNED_BYTE, vertexBuffer);

    // Disable the vertices buffer.
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    // Disable face culling.
    gl.glDisable(GL10.GL_CULL_FACE);
}

The program is currently crashing when draw () is called;

Thank!

+3
source share
1 answer

glDrawElements. , , ( glVertexPointer).

private unsigned byte indices[] = { 0, 1, 2, 3 };
...
gl.glDrawElements(GL10.GL_POINTS, 4, GL10.GL_UNSIGNED_BYTE, indices);

- ,

gl.glDrawArrays(GL10.GL_POINTS, 0, 4);

glDrawElements.

: , , , glDrawElements vertexBuffer 4 ( 0 3).

+5

All Articles