Example usage for org.lwjgl.opengl GL15 glBindBuffer

List of usage examples for org.lwjgl.opengl GL15 glBindBuffer

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL15 glBindBuffer.

Prototype

public static void glBindBuffer(@NativeType("GLenum") int target, @NativeType("GLuint") int buffer) 

Source Link

Document

Binds a named buffer object.

Usage

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

protected void createVBO() {
    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length * Vertex.elementCount);
    for (int i = 0; i < vertices.length; i++) {
        verticesBuffer.put(vertices[i].getElements());
    }/*from   ww  w  .ja va2  s. c  o  m*/
    verticesBuffer.flip();

    // Create the indices buffer and place the data in it.
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesData.length);
    indicesBuffer.put(indicesData);
    indicesBuffer.flip();

    // Initialize the VAO 
    vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    // Initialize the VBO 
    vboVerticesId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVerticesId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);

    // Put the positions in attribute list 0
    GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride,
            Vertex.positionByteOffset);
    // Put the color components in attribute list 1
    GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride,
            Vertex.colorByteOffset);
    // Put the texture coordinates in attribute list 2
    GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride,
            Vertex.textureByteOffset);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    // Deselect the VAO
    GL30.glBindVertexArray(0);

    // Create a VBO for the indices.
    vboIndicesId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboIndicesId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

/**
 * Render the Object.//w  w w .j a  v  a 2 s  .c o m
 */
public void render() {
    FloatBuffer matrix44Buffer = BufferUtils.createFloatBuffer(16);
    modelMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(ShaderProgram.getMML(), false, matrix44Buffer);

    // Bind the texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // Bind to the VAO that has all the information about the quad vertices
    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    // Bind to the index VBO that has all the information about the order of the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboIndicesId);

    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesData.length, GL11.GL_UNSIGNED_BYTE, 0);

    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(2);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
}

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

public void destroy() {
    // Disable the VBO index from the VAO attributes list
    GL20.glDisableVertexAttribArray(0);/*w ww  .  j a  v a  2 s . com*/

    // Delete the vertex VBO
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboVerticesId);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboIndicesId);

    // Delete the VAO
    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(vaoId);
}

From source file:com.google.gapid.glviewer.gl.Buffer.java

License:Apache License

public Buffer bind() {
    GL15.glBindBuffer(target, handle);
    return this;
}

From source file:com.google.gapid.glviewer.gl.IndexBuffer.java

License:Apache License

void bind() {
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, handle);
}

From source file:com.google.gapid.glviewer.gl.VertexBuffer.java

License:Apache License

void bind() {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, handle);
}

From source file:com.grillecube.client.opengl.GLVertexBuffer.java

/** bind the vbo */
public void bind(int target) {
    GL15.glBindBuffer(target, this.glID);
}

From source file:com.grillecube.client.opengl.GLVertexBuffer.java

/** unbind the vbo */
public void unbind(int target) {
    GL15.glBindBuffer(target, 0);
}

From source file:com.grillecube.engine.opengl.object.GLVertexBuffer.java

/** bind the vbo */
public void bind(int target) {
    GL15.glBindBuffer(target, this._id);
}

From source file:com.mtbs3d.minecrift.MCOculus.java

License:LGPL

public void endFrame() {
    GL11.glDisable(GL11.GL_CULL_FACE); // Oculus wants CW orientations, avoid the problem by turning off culling...
    GL11.glDisable(GL11.GL_DEPTH_TEST); // Nothing is drawn with depth test on...

    // End the frame
    super.endFrame();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Unbind GL_ARRAY_BUFFER for my own vertex arrays to work...
    GL11.glEnable(GL11.GL_CULL_FACE); // Turn back on...
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Turn back on...
    GL11.glClearDepth(1); // Oculus set this to 0 (the near plane), return to normal...
    ARBShaderObjects.glUseProgramObjectARB(0); // Oculus shader is still active, turn it off...

    Display.processMessages();/*w w w  .  j  av  a  2  s  .c  o  m*/
}