Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class VBO {
- public VBO(Vertex[] vertices, int[] indices, float[] colors, int usage, BasicShader shader){
- //3 = x, y and z, don't know if you can only use x and y
- FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length * 4);
- for(int i = 0; i < vertices.length; i++){
- verticesBuffer.put(new float[]{
- vertices[i].getPos().getX(),
- vertices[i].getPos().getY(),
- 0f, 1f, //z, w
- });
- }
- verticesBuffer.flip();
- vboPointer = GL15.glGenBuffers();
- GL30.glBindVertexArray(vboPointer);
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboPointer);
- GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, usage);
- GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, 0, 0);
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- //TODO: REMOVE THIS
- FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(colors.length);
- colorBuffer.put(colors);
- colorBuffer.flip();
- colorPointer = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colorPointer);
- GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colorBuffer, usage);
- GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, 0, 0);
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- this.shader = shader;
- GL30.glBindVertexArray(0);
- indicesCount = indices.length;
- IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indicesCount);
- indicesBuffer.put(indices);
- indicesBuffer.flip();
- iboPointer = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, iboPointer);
- GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, usage);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
- }
- private int vboPointer;
- private int iboPointer;
- private int colorPointer;
- private int indicesCount = 0;
- private BasicShader shader;
- public void render(Renderer renderer){
- shader.useProgram();
- GL30.glBindVertexArray(vboPointer);
- GL20.glEnableVertexAttribArray(0);
- GL20.glEnableVertexAttribArray(1);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, iboPointer);
- GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_INT, 0);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
- GL20.glDisableVertexAttribArray(0);
- GL20.glDisableVertexAttribArray(1);
- GL30.glBindVertexArray(0);
- shader.delselectProgram();
- }
- public int getVerticesPointer(){
- return vboPointer;
- }
- public int getIndicesPointer(){
- return iboPointer;
- }
- public int getColorPointer(){
- return colorPointer;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement