In the create method:
1 2 3 4 5 6 7 8 9 10 11 12 | public void create() { ... //create VBO and pass in vertex attributes object vertisees = new VertexBufferObject( false, (vertices.length / 7 ), vAs ); ... //let OGL know where vertex data is vertisees.bind( shaderProgram ); //internally calls gdx.gl.bindbuffer && gdx.gl.glBufferData vertisees.setVertices( vertices, 0, vertices.length ); } |
Then to render:
1 2 3 4 5 6 7 8 | public void render () { ... //draw the points on the screen Gdx.gl.glDrawArrays( Gdx.gl.GL_POINTS, 0, vertisees.getNumVertices() ); ... } |
We can replace explicitly creating the VBO by using the Mesh.java class as seen in action in the Meshes section of the libGDX wiki. By following that example, we get:
1 2 3 4 5 6 7 | public void create() { ... //create Mesh with Vertex Attribute objects mesh = new Mesh( true, (vertices.length / 7 ), 0, vA, vC ); mesh.setVertices( vertices ); } |
and in the render function:
1 2 3 4 5 6 7 8 | public void render () { ... //draw the points on the screen mesh.render( shaderProgram, Gdx.gl.GL_POINTS ); //internally calls bind(), unbind(), and .glDrawArrays() ... } |
As the code comment mentions, the .render() function of the Mesh class calls the bind() and unbind() functions (using the shader program object we passed in) of the VBO internally created by the Mesh object. In between the calls to bind() and unbind(), .glDrawArrays is called.
To summarize, we replaced creating a VBO, an explicit call to that VBO's .bind() function and a call to .glDrawArrays by using libGDX's Mesh class.
Next.