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:ivorius.ivtoolkit.models.data.IndexBufferObject.java

License:Apache License

@Override
public void dispose() {
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    if (bufferHandle > 0)
        GL15.glDeleteBuffers(bufferHandle);
    bufferHandle = 0;//from   w w  w.ja v  a 2  s .  co  m
}

From source file:ivorius.ivtoolkit.models.data.VertexBufferObject.java

License:Apache License

/**
 * Disposes of all resources this VertexBufferObject uses.
 *///ww  w .  j  a  va 2  s .  c o  m
@Override
public void dispose() {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    if (bufferHandle > 0)
        GL15.glDeleteBuffers(bufferHandle);
    bufferHandle = 0;
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl15.java

License:Open Source License

@Override
public void bindBuffer(int target, int buffer) {
    GL15.glBindBuffer(bufferTargetToGL[target], buffer);
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

private void SetupEntity(Vector3f[] vertex, Vector3f[] color, Vector2f[] uv) {

    // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class
    vertices = new VertexData[vertex.length];

    for (int i = 0; i < vertex.length; i++) {
        vertices[i] = new VertexData();
        vertices[i].setXYZ(vertex[i].x, vertex[i].y, vertex[i].z);
        vertices[i].setRGBA(color[i].x, color[i].y, color[i].z, 1.0f);
        vertices[i].setST(uv[i].x, uv[i].y);
    }//from   w  w w.j  a va 2s  .  c  om

    // Put each 'Vertex' in one FloatBuffer
    verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * VertexData.stride);
    FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer();
    for (int i = 0; i < vertices.length; i++) {
        // Add position, color and texture floats to the buffer
        verticesFloatBuffer.put(vertices[i].getElements());
    }
    verticesFloatBuffer.flip();

    // OpenGL expects to draw vertices in counter clockwise order by default
    // TODO: Move this to Setup.
    byte[] indices = { 0, 1, 2, 2, 3, 0 };

    indicesCount = indices.length;
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
    indicesBuffer.put(indices);
    indicesBuffer.flip();

    // Create a new Vertex Array Object in memory and select it (bind)
    vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    // Create a new Vertex Buffer Object in memory and select it (bind)
    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STREAM_DRAW);

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

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

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

    // Create a new VBO for the indices and select it (bind) - INDICES
    vboiId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    Game.cameraPos = new Vector3f(0, 0, -1);

    Game.exitOnGLError("setupQuad");
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

@Override
public void Render(float interpolation) {

    GL20.glUseProgram(pId);/*from  w ww  . ja  v a2s. c om*/

    // 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 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, vboiId);

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

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

    GL20.glUseProgram(0);

    Game.exitOnGLError("renderCycle");
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

public void destroy() {
    // Delete the Program
    GL20.glUseProgram(0);/*from w ww  .j  a  v  a2s  .  c  o m*/
    GL20.glDeleteProgram(pId);

    // Select the VAO
    GL30.glBindVertexArray(vaoId);

    // Disable the VBO index from the VAO attributes list
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);

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

    // Delete the index VBO
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboiId);

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

From source file:main.Loader.java

private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) {
    int vboID = GL15.glGenBuffers();
    vbos.add(vboID);/*from ww w  .ja v  a 2s. c o  m*/
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
    FloatBuffer buffer = storeDataInFloatBuffer(data);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:main.Loader.java

private void bindIndicesBuffer(int[] indices) {
    int vboID = GL15.glGenBuffers();
    vbos.add(vboID);//from  w ww.  j  a  va2 s. c om
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID);
    IntBuffer buffer = storeDataInIntBuffer(indices);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
}

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

public void resizeBuffer() {
    vertByteBuff = BufferUtils.createByteBuffer(vertexCount * Vertex.stride);
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
    FloatBuffer vertFloatBuff = vertByteBuff.asFloatBuffer();
    for (Drawable object : objects) {
        object.store(vertFloatBuff);/* w  ww.j  a va  2  s  .  c o m*/
        indicesBuffer.put(object.getIndices());
    }
    for (Drawable object : orthoObjects) {
        object.store(vertFloatBuff);
        indicesBuffer.put(object.getIndices());
    }
    indicesBuffer.flip();
    vertFloatBuff.flip();
    GL30.glBindVertexArray(vaoId);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertFloatBuff, GL15.GL_STREAM_DRAW);
    GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, Vertex.stride, 0);
    GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, Vertex.stride, 16);
    GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, Vertex.stride, 32);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

private synchronized void logic() {
    if (invalidated) {
        invalidated = false;//  w  ww .  j a v  a  2s. c o m
        resizeBuffer();
    }
    mvpMat = cam.getMVP();
    if (vertexCount == 0)
        return;
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    int offset = 0;
    FloatBuffer vertFloatBuff = vertByteBuff.asFloatBuffer();
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, offset, vertByteBuff);
    vertFloatBuff.rewind();
    for (Drawable object : objects) {
        object.store(vertFloatBuff);
    }
    for (Drawable object : orthoObjects) {
        object.store(vertFloatBuff);
    }
    vertFloatBuff.flip();
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, offset, vertByteBuff);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    // GL20.glUseProgram(shader.getPID());
    // mvpMat.get(0, matBuff);
    // // matBuff.flip();
    // // matBuff.put(0,5.0f);
    // GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff);
    // GL20.glUseProgram(0);
}