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.xrbpowered.gl.res.shaders.InstanceBuffer.java

License:Open Source License

public void disable() {
    for (int i = 0; i < elemCount.length; i++)
        GL20.glDisableVertexAttribArray(attribId + i);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:com.xrbpowered.gl.res.StaticMesh.java

License:Open Source License

private void create(VertexInfo info, FloatBuffer vertexBuffer, ShortBuffer indexBuffer, int countElements,
        int verticesPerElement, boolean dynamic) {
    this.countElements = countElements;
    this.drawMode = getDrawMode(verticesPerElement);
    int usage = dynamic ? GL15.GL_DYNAMIC_DRAW : GL15.GL_STATIC_DRAW;

    vaoId = GL30.glGenVertexArrays();/*from  w  ww .j  a v  a  2 s.c om*/
    GL30.glBindVertexArray(vaoId);

    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexBuffer, usage);

    this.countAttribs = info.getAttributeCount();
    info.initAttribPointers();

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

    if (indexBuffer != null) {
        vboiId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuffer, usage);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    }
}

From source file:com.xrbpowered.gl.res.StaticMesh.java

License:Open Source License

public void disableDraw() {
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    for (int i = 0; i < countAttribs; i++)
        GL20.glDisableVertexAttribArray(i);
    GL30.glBindVertexArray(0);/*from w w w .  ja v  a2 s  .  c  o m*/
}

From source file:com.xrbpowered.gl.res.StaticMesh.java

License:Open Source License

public void drawCallInstanced(int count) {
    if (vboiId != GL11.GL_INVALID_VALUE) {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL31.glDrawElementsInstanced(drawMode, countElements, GL11.GL_UNSIGNED_SHORT, 0, count);
    } else {/*from ww  w.j a v a 2s . c  o  m*/
        GL31.glDrawArraysInstanced(drawMode, 0, countElements, count);
    }
}

From source file:com.xrbpowered.gl.res.StaticMesh.java

License:Open Source License

public void drawCall() {
    if (vboiId != GL11.GL_INVALID_VALUE) {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL11.glDrawElements(drawMode, countElements, GL11.GL_UNSIGNED_SHORT, 0);
    } else {/*from w w w .j a v  a 2 s .c  o m*/
        GL11.glDrawArrays(drawMode, 0, countElements);
    }
}

From source file:com.xrbpowered.gl.res.StaticMesh.java

License:Open Source License

public void destroy() {
    GL30.glBindVertexArray(vaoId);//from  w w w  .j  a v a  2s  . c  o  m
    for (int i = 0; i < countAttribs; i++)
        GL20.glDisableVertexAttribArray(i);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboId);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    if (vboiId != GL11.GL_INVALID_VALUE)
        GL15.glDeleteBuffers(vboiId);
    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(vaoId);
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public int createIndexBuffer16(short data[]) {
    int id = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, id);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW);
    return id;/*w  w  w  .  ja va 2  s .com*/
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void setIndexBuffer(int ib) {
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ib);
}

From source file:cuchaz.jfxgl.prism.TexturedQuad.java

License:Open Source License

public TexturedQuad(int x, int y, int w, int h, int texId, Shader shader) {

    this.shader = shader;
    this.texId = texId;

    // make the vertex array
    vaoId = GL30.glGenVertexArrays();/*ww  w  .ja  v  a 2  s.c o m*/
    GL30.glBindVertexArray(vaoId);

    try (MemoryStack m = MemoryStack.stackPush()) {

        // make the indices
        ByteBuffer indexBuf = m.bytes(new byte[] { 0, 1, 2, 0, 2, 3 });
        iboId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, iboId);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, indexBuf, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, iboId);

        // make the vertices
        FloatBuffer vertexBuf = m.floats(
                new float[] { x + 0, y + 0, 0, 0, x + w, y + 0, 1, 0, x + w, y + h, 1, 1, x + 0, y + h, 0, 1 });
        vboId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexBuf, GL15.GL_STATIC_DRAW);
        GL20.glEnableVertexAttribArray(0);
        GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, Float.BYTES * 4, 0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, Float.BYTES * 4, Float.BYTES * 2);
    }

    // unbind things
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
}

From source file:Data.Building.java

License:Apache License

@Override
public void setup() {
    // OpenGL expects vertices to be defined counter clockwise by default

    triangulize(geometry);//from w ww.  jav  a2s  .  c o m

    // Sending data to OpenGL requires the usage of (flipped) byte buffers
    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
    verticesBuffer.put(vertices);
    verticesBuffer.flip();

    vertexCount = vertices.length;

    // Create a new Vertex Array Object in memory and select it (bind)
    // A VAO can have up to 16 attributes (VBO's) assigned to it by default
    vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    // Create a new Vertex Buffer Object in memory and select it (bind)
    // A VBO is a collection of Vectors which in this case resemble the location of each vertex.
    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
    // Put the VBO in the attributes list at index 0
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
    // Deselect (bind to 0) the VBO
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

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

    Util.exitOnGLError("Error in setupQuad");
}