Example usage for org.lwjgl.opengl GL15 glGenBuffers

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

Introduction

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

Prototype

@NativeType("void")
public static int glGenBuffers() 

Source Link

Document

Generates buffer object names.

Usage

From source file:com.timvisee.voxeltex.module.mesh.Mesh.java

License:Open Source License

/**
 * Build and buffer the mesh on the graphics card.
 *//*from   w w w. ja v a2 s . c om*/
public void bufferMesh() {
    // Create a flipped float buffer for the vertexes
    this.vertexBuffer = BufferUtils
            .createFloatBuffer(this.raw.getVertexCount() * this.raw.getVertexAxisCount());
    this.vertexBuffer.put(this.raw.getVertexes());
    this.vertexBuffer.flip();

    // Create a VBO handle for the vertexes and bind the buffer
    vboVertexHandle = GL15.glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, this.vboVertexHandle);
    GL15.glBufferData(GL_ARRAY_BUFFER, this.vertexBuffer, GL15.GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    // Buffer the normal data if the mesh has any configured
    if (this.raw.hasNormalData()) {
        // Create a flipped float buffer for the normal coordinates
        this.normalBuffer = BufferUtils
                .createFloatBuffer(this.raw.getNormalCount() * this.raw.getNormalAxisCount());
        this.normalBuffer.put(this.raw.getNormals());
        this.normalBuffer.flip();

        // Create a VBO handle for the normal coordinates and bind the buffer
        vboNormalHandle = GL15.glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, this.vboNormalHandle);
        GL15.glBufferData(GL_ARRAY_BUFFER, this.normalBuffer, GL15.GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
    }

    // Buffer the texture data if the mesh has any configured
    if (this.raw.hasTextureData()) {
        // Create a flipped float buffer for the texture coordinates
        this.textureBuffer = BufferUtils
                .createFloatBuffer(this.raw.getVertexCount() * this.raw.getTextureAxisCount());
        this.textureBuffer.put(this.raw.getTextures());
        this.textureBuffer.flip();

        // Create a VBO handle for the texture coordinates and bind the buffer
        vboTextureHandle = GL15.glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, this.vboTextureHandle);
        GL15.glBufferData(GL_ARRAY_BUFFER, this.textureBuffer, GL15.GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
    }

    // Set the number of vertexes and normals
    this.vertexCount = this.raw.getVertexCount();
    this.normalCount = this.raw.getNormalCount();
}

From source file:com.voxelplugineering.voxelsniper.render.buffer.BufferSection.java

License:Open Source License

public void create(int vaoId) {
    build();/*from   www  . j a v a2  s  . c  om*/

    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, RenderingConstants.POSITION_ELEMENT_COUNT, GL11.GL_FLOAT, false,
            RenderingConstants.STRIDE, RenderingConstants.POSITION_BYTE_OFFSET);
    // Put the color components in attribute list 1
    GL20.glVertexAttribPointer(1, RenderingConstants.COLOUR_ELEMENT_COUNT, GL11.GL_FLOAT, false,
            RenderingConstants.STRIDE, RenderingConstants.COLOUR_BYTE_OFFSET);
    // Put the texture coordinates in attribute list 2
    GL20.glVertexAttribPointer(2, RenderingConstants.TEXTURE_ELEMENT_COUNT, GL11.GL_FLOAT, false,
            RenderingConstants.STRIDE, RenderingConstants.TEXTURE_BYTE_OFFSET);

    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);
}

From source file:com.xrbpowered.gl.res.shaders.FeedbackVertices.java

License:Open Source License

public FeedbackVertices(Shader transformShader, Shader renderShader, int count, boolean createIndices) {
    this.transformShader = transformShader;
    this.renderShader = renderShader;
    this.countElements = count;
    vertexBuffer = BufferUtils.createByteBuffer(count * transformShader.info.getStride()).asFloatBuffer();
    feedbackBuffer = BufferUtils.createByteBuffer(count * renderShader.info.getStride()).asFloatBuffer();

    vaoId = GL30.glGenVertexArrays();//from   w ww .  j av a 2  s . c  o  m
    GL30.glBindVertexArray(vaoId);

    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, count * transformShader.info.getStride(), GL15.GL_DYNAMIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    vboFeedbackId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboFeedbackId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, count * renderShader.info.getStride(), GL15.GL_DYNAMIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL30.glBindVertexArray(0);

    if (createIndices) {
        indexBuffer = BufferUtils.createByteBuffer(count * 4).asIntBuffer();

        vboiId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, count * 4, GL15.GL_DYNAMIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    }
    Client.checkError();
}

From source file:com.xrbpowered.gl.res.shaders.InstanceBuffer.java

License:Open Source License

public InstanceBuffer(int divisor, int count, int attribId, int[] elemCount) {
    this.divisor = divisor;
    this.attribId = attribId;
    this.elemCount = elemCount;
    stride = 0;//from  www .ja va 2s .  co m
    for (int i = 0; i < elemCount.length; i++) {
        stride += 4 * elemCount[i];
    }
    instanceBuffer = BufferUtils.createByteBuffer(count * stride).asFloatBuffer();

    iboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, iboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, count * stride, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    Client.checkError();
}

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 va 2s .  c  o  m
    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: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;//from   w  w w .  j av  a  2 s  . com
}

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();//  w  w  w . ja va2 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  . j a va2s . 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");
}

From source file:dataAccess.lwjgl.VAO_Loader.java

/**
 * Stores data in an attribute list of a VAO.
 *
 * @param vaoID The id of the VAO to which data will be added.
 * @param attributeNumber The number of the attribute list in which the data
 * will be stored./*from   w ww .  j av  a2  s  . c o m*/
 * @param data The data that will be stored in the attribute list.
 */
private static void storeDataInAttributeList(int vaoID, int attributeNumber, int coordinateSize, float[] data) {
    // bind VAO so that it can be used.
    bindVAO(vaoID);

    // Create new VBO.
    int vboID = GL15.glGenBuffers();

    // Adds VBO to list so that it can be cleared when needed.
    vbos.add(vboID);

    // VBO has to be bound aswel.
    bindArrayBuffer(vboID);

    // Converts float array to an instance of FloatBuffer, which can
    // be stored in a VBO.
    FloatBuffer buffer = Convert.toReadableFloatBuffer(data);

    // Puts the buffer into the VBO, and GL_STATIC_DRAW tells it that it 
    // won't ever be modified.
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);

    // Specifies that this is for the Vertex Array.
    GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);

    // Unbind the VBO.
    unbindArrayBuffer();

    // unbind VAO so that another may be bound.
    unbindVAO();
}

From source file:dataAccess.lwjgl.VAO_Loader.java

/**
 * Stores data in an attribute list of a VAO.
 *
 * @param vaoID The id of the VAO to which data will be added.
 * @param attributeNumber The number of the attribute list in which the data
 * will be stored.//ww w .  jav a  2  s .  co m
 * @param data The data that will be stored in the attribute list.
 */
private static void bindIndicesBuffer(int vaoID, int[] data) {
    // bind VAO so that it can be used.
    bindVAO(vaoID);

    // Create new VBO.
    int vboID = GL15.glGenBuffers();

    // Adds VBO to list so that it can be cleared when needed.
    vbos.add(vboID);

    // VBO has to be bound aswel.
    bindElementArrayBuffer(vboID);

    // Converts int array to an instance of IntBuffer, which can
    // be stored in a VBO.
    IntBuffer buffer = Convert.toReadableIntBuffer(data);

    // Puts the buffer into the VBO, and GL_STATIC_DRAW tells it that it 
    // won't ever be modified.
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);

    // Unbind the VBO.
    //unbindElementArrayBuffer();
    // unbind VAO so that another may be bound.
    unbindVAO();
}