Example usage for org.lwjgl.opengl GL20 glVertexAttribPointer

List of usage examples for org.lwjgl.opengl GL20 glVertexAttribPointer

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 glVertexAttribPointer.

Prototype

public static void glVertexAttribPointer(@NativeType("GLuint") int index, @NativeType("GLint") int size,
        @NativeType("GLenum") int type, @NativeType("GLboolean") boolean normalized,
        @NativeType("GLsizei") int stride, @NativeType("void const *") FloatBuffer pointer) 

Source Link

Document

Specifies the location and organization of a vertex attribute array.

Usage

From source file:eu.over9000.veya.rendering.ChunkVAO.java

License:Open Source License

public void create() {
    // create objects

    if (holdsSolid) {
        this.ibo_handle_solid = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_handle_solid);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_buffer_solid, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        this.vbo_handle_solid = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo_handle_solid);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, this.vbo_buffer_solid, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        this.vao_handle_solid = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(this.vao_handle_solid);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo_handle_solid);
        GL20.glEnableVertexAttribArray(0);
        GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.positionByteOffset);

        GL20.glEnableVertexAttribArray(1);
        GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.colorByteCount);//from   www .  ja  va  2  s  . c o  m

        GL20.glEnableVertexAttribArray(2);
        GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.textureByteOffset);

        GL20.glEnableVertexAttribArray(3);
        GL20.glVertexAttribPointer(3, Vertex.normalElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.normalByteOffset);

        GL20.glEnableVertexAttribArray(4);
        GL20.glVertexAttribPointer(4, Vertex.aoElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.aoByteOffset);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_handle_solid);

        GL30.glBindVertexArray(0);
    }

    if (holdsTransparent) {
        this.ibo_handle_transparent = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_handle_transparent);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_buffer_transparent, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        this.vbo_handle_transparent = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo_handle_transparent);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, this.vbo_buffer_transparent, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        this.vao_handle_transparent = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(this.vao_handle_transparent);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo_handle_transparent);
        GL20.glEnableVertexAttribArray(0);
        GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.positionByteOffset);

        GL20.glEnableVertexAttribArray(1);
        GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.colorByteOffset);

        GL20.glEnableVertexAttribArray(2);
        GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.textureByteOffset);

        GL20.glEnableVertexAttribArray(3);
        GL20.glVertexAttribPointer(3, Vertex.normalElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.normalByteOffset);

        GL20.glEnableVertexAttribArray(4);
        GL20.glVertexAttribPointer(4, Vertex.aoElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.aoByteOffset);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_handle_transparent);

        GL30.glBindVertexArray(0);
    }

    // System.out.println("created ChunkVAO with " + this.vertexData.length + " vertices");
}

From source file:eu.over9000.veya.rendering.Shadow.java

License:Open Source License

public void renderQuad() {
    if (quadVAO == 0) {
        final float[] quadVertices = {
                // Positions        // Texture Coords
                -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
                1.0f, -1.0f, 0.0f, 1.0f, 0.0f, };
        // Setup plane VAO

        final FloatBuffer fb = BufferUtils.createFloatBuffer(quadVertices.length);

        fb.put(quadVertices);//from w  w w .  j  a v  a 2 s . c o  m
        fb.flip();

        quadVAO = GL30.glGenVertexArrays();
        quadVBO = GL15.glGenBuffers();
        GL30.glBindVertexArray(quadVAO);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, quadVBO);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, fb, GL15.GL_STATIC_DRAW);
        GL20.glEnableVertexAttribArray(0);
        GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 5 * Float.BYTES, 0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 5 * Float.BYTES, 3 * Float.BYTES);
    }
    GL30.glBindVertexArray(quadVAO);
    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);
    GL30.glBindVertexArray(0);
}

From source file:fr.guillaume.prive.viper.core.graphic.GraphicMotor.java

private static void setupObjModels() {
    ObjModel spaceShipModel = ObjLoader.loadModel(new File("resources/model/fighter.obj"));
    FloatBuffer verticesBuffer = BufferUtils
            .createFloatBuffer(Vertex.ELEMENT_COUNT * spaceShipModel.getVertices().size());
    spaceShipModel.getVertices().stream().forEach((v) -> verticesBuffer.put(v.getElements()));
    verticesBuffer.flip();/*  ww  w.  j a va2 s  .  c o  m*/

    instance.shipVaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(instance.shipVaoId);
    instance.shipVboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, instance.shipVboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(0, Vertex.POSITION_ELEMENT_COUNT, GL11.GL_FLOAT, false, Vertex.STRIDE, 0);
    GL20.glVertexAttribPointer(1, Vertex.NORMAL_ELEMENT_COUNT, GL11.GL_FLOAT, false, Vertex.STRIDE,
            Vertex.NORMAL_BYTE_OFFSET);
    GL20.glVertexAttribPointer(2, Vertex.COLOR_ELEMENT_COUNT, GL11.GL_FLOAT, false, Vertex.STRIDE,
            Vertex.COLOR_BYTE_OFFSET);
    GL20.glVertexAttribPointer(3, Vertex.TEXTURE_ELEMENT_COUNT, GL11.GL_FLOAT, false, Vertex.STRIDE,
            Vertex.TEXTURE_BYTE_OFFSET);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);

    instance.shipVboiLenght = spaceShipModel.getIndices().length;
    IntBuffer indicesBuffer = BufferUtils.createIntBuffer(instance.shipVboiLenght);
    indicesBuffer.put(spaceShipModel.getIndices());
    indicesBuffer.flip();
    instance.shipVboiId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, instance.shipVboiId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}

From source file:fr.ign.cogit.geoxygene.appli.gl.GLBezierShadingComplex.java

License:Open Source License

/**
 * Bind Buffers with gl Context/*w w w  .  j av a 2  s  .co  m*/
 */
private void generateVao() {
    // Create a new Vertex Array Object in memory and select it (bind)
    this.vaoId = GL30.glGenVertexArrays();
    if (this.vaoId <= 0) {
        logger.error("VAO ID is invalid " + this.vaoId);
    }
    glBindVertexArray(this.vaoId);

    // create the Vertex VBO
    this.vboVerticesId = glGenBuffers();
    if (this.vboVerticesId <= 0) {
        logger.error("VBO(Vertices) ID is invalid " + this.vboVerticesId);
    }
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vboVerticesId);

    int byteShift = 0;
    for (GLInput input : this.getInputs()) {
        GL20.glVertexAttribPointer(input.getLocation(), input.getComponentCount(), input.getGlType(),
                input.isNormalized(), this.getStride(), byteShift);
        // System.err
        // .println("loc = " + input.getLocation() + " "
        // + input.getComponentCount() + " "
        // + input.getGlType() + " stride = "
        // + this.getStride() + " shift = " + byteShift);
        byteShift += input.getComponentCount() * GLTools.sizeInBytes(input.getGlType());
        glEnableVertexAttribArray(input.getLocation());

    }
    glBufferData(GL_ARRAY_BUFFER, this.getFlippedVerticesBuffer(), GL_STATIC_DRAW);
    // create the index VBO
    this.vboIndicesId = glGenBuffers();
    if (this.vboIndicesId <= 0) {
        logger.error("VBO(Indices) ID is invalid " + this.vboIndicesId);
    }
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.vboIndicesId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this.getFlippedIndicesBuffer(), GL_STATIC_DRAW);
    glBindVertexArray(0);
}

From source file:fr.ign.cogit.geoxygene.appli.gl.GLPaintingComplex.java

License:Open Source License

/**
 * Bind Buffers with gl Context/*from w w  w  . j  a  v a  2 s.  c  o m*/
 */
private void generateVao() {
    // Create a new Vertex Array Object in memory and select it (bind)
    this.vaoId = GL30.glGenVertexArrays();
    if (this.vaoId <= 0) {
        logger.error("VAO ID is invalid " + this.vaoId);
    }
    glBindVertexArray(this.vaoId);

    // create the Vertex VBO
    this.vboVerticesId = glGenBuffers();
    if (this.vboVerticesId <= 0) {
        logger.error("VBO(Vertices) ID is invalid " + this.vboVerticesId);
    }
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vboVerticesId);

    int byteShift = 0;
    for (GLInput input : this.getInputs()) {
        GL20.glVertexAttribPointer(input.getLocation(), input.getComponentCount(), input.getGlType(),
                input.isNormalized(), this.getStride(), byteShift);
        // System.err.println("loc = " + input.getLocation() + " "
        // + input.getComponentCount() + " " + input.getGlType()
        // + " stride = " + this.getStride() + " shift = " + byteShift
        // + " name = " + input.getName() + " ("
        // + this.getClass().getSimpleName() + ")");
        byteShift += input.getComponentCount() * GLTools.sizeInBytes(input.getGlType());
        glEnableVertexAttribArray(input.getLocation());

    }
    // System.err.println("previous");
    // for (int nAttrib = 0; nAttrib < GLSimpleVertex.ATTRIBUTES_COUNT;
    // nAttrib++)
    // {
    // GL20.glVertexAttribPointer(GLSimpleVertex.ATTRIBUTES_ID[nAttrib],
    // GLSimpleVertex.ATTRIBUTES_COMPONENT_NUMBER[nAttrib],
    // GLSimpleVertex.ATTRIBUTES_TYPE[nAttrib],
    // false, GLSimpleVertex.VERTEX_BYTESIZE,
    // GLSimpleVertex.ATTRIBUTES_BYTEOFFSET[nAttrib]);
    // System.err.println("loc = " + GLSimpleVertex.ATTRIBUTES_ID[nAttrib] +
    // " " +
    // GLSimpleVertex.ATTRIBUTES_COMPONENT_NUMBER[nAttrib] + " "
    // + GLSimpleVertex.ATTRIBUTES_TYPE[nAttrib] + " stride = " +
    // GLSimpleVertex.VERTEX_BYTESIZE + " shift = " +
    // GLSimpleVertex.ATTRIBUTES_BYTEOFFSET[nAttrib]);
    // glEnableVertexAttribArray(GLSimpleVertex.ATTRIBUTES_ID[nAttrib]);
    //
    // }

    glBufferData(GL_ARRAY_BUFFER, this.getFlippedVerticesBuffer(), GL_STATIC_DRAW);
    // System.err
    // .println("Buffer  la construction ********************************");
    // GLTools.displayBuffer(this.getFlippedVerticesBuffer());
    // System.err
    // .println("Buffer  la construction ---------------------------------");

    // glBindBuffer(GL_ARRAY_BUFFER, 0);

    // create the index VBO
    this.vboIndicesId = glGenBuffers();
    if (this.vboIndicesId <= 0) {
        logger.error("VBO(Indices) ID is invalid " + this.vboIndicesId);
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.vboIndicesId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this.getFlippedIndicesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedIndicesBuffer());

    glBindVertexArray(0);

}

From source file:fr.ign.cogit.geoxygene.appli.gl.GLSimpleComplex.java

License:Open Source License

/**
 * Bind Buffers with gl Context//ww  w.  j a  v a2 s  .  c  o  m
 */
private void generateVao() {
    // Create a new Vertex Array Object in memory and select it (bind)
    this.vaoId = GL30.glGenVertexArrays();
    if (this.vaoId <= 0) {
        logger.error("VAO ID is invalid " + this.vaoId);
    }
    glBindVertexArray(this.vaoId);

    // create the Vertex VBO
    this.vboVerticesId = glGenBuffers();
    if (this.vboVerticesId <= 0) {
        logger.error("VBO(Vertices) ID is invalid " + this.vboVerticesId);
    }
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vboVerticesId);

    int byteShift = 0;
    for (GLInput input : this.getInputs()) {
        GL20.glVertexAttribPointer(input.getLocation(), input.getComponentCount(), input.getGlType(),
                input.isNormalized(), this.getStride(), byteShift);
        byteShift += input.getComponentCount() * GLTools.sizeInBytes(input.getGlType());
        glEnableVertexAttribArray(input.getLocation());

    }

    glBufferData(GL_ARRAY_BUFFER, this.getFlippedVerticesBuffer(), GL_STATIC_DRAW);
    // create the index VBO
    this.vboIndicesId = glGenBuffers();
    if (this.vboIndicesId <= 0) {
        logger.error("VBO(Indices) ID is invalid " + this.vboIndicesId);
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.vboIndicesId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this.getFlippedIndicesBuffer(), GL_STATIC_DRAW);

    glBindVertexArray(0);

}

From source file:fr.ign.cogit.geoxygene.appli.gl.GLTextComplex.java

License:Open Source License

/**
 * Bind Buffers with gl Context//w w w .ja  va2  s .  c o  m
 */
private void generateVao() {
    // Create a new Vertex Array Object in memory and select it (bind)
    this.vaoId = GL30.glGenVertexArrays();
    if (this.vaoId <= 0) {
        logger.error("VAO ID is invalid " + this.vaoId);
    }
    glBindVertexArray(this.vaoId);

    // create the Vertex VBO
    this.vboVerticesId = glGenBuffers();
    if (this.vboVerticesId <= 0) {
        logger.error("VBO(Vertices) ID is invalid " + this.vboVerticesId);
    }
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vboVerticesId);

    int byteShift = 0;
    for (GLInput input : this.getInputs()) {
        GL20.glVertexAttribPointer(input.getLocation(), input.getComponentCount(), input.getGlType(),
                input.isNormalized(), this.getStride(), byteShift);
        // System.err.println("loc = " + input.getLocation() + " "
        // + input.getComponentCount() + " " + input.getGlType()
        // + " stride = " + this.getStride() + " shift = " + byteShift
        // + " name = " + input.getName() + " "
        // + this.getClass().getSimpleName());
        byteShift += input.getComponentCount() * GLTools.sizeInBytes(input.getGlType());
        glEnableVertexAttribArray(input.getLocation());

    }
    // System.err.println("previous");
    // for (int nAttrib = 0; nAttrib < GLSimpleVertex.ATTRIBUTES_COUNT;
    // nAttrib++)
    // {
    // GL20.glVertexAttribPointer(GLSimpleVertex.ATTRIBUTES_ID[nAttrib],
    // GLSimpleVertex.ATTRIBUTES_COMPONENT_NUMBER[nAttrib],
    // GLSimpleVertex.ATTRIBUTES_TYPE[nAttrib],
    // false, GLSimpleVertex.VERTEX_BYTESIZE,
    // GLSimpleVertex.ATTRIBUTES_BYTEOFFSET[nAttrib]);
    // System.err.println("loc = " + GLSimpleVertex.ATTRIBUTES_ID[nAttrib] +
    // " " +
    // GLSimpleVertex.ATTRIBUTES_COMPONENT_NUMBER[nAttrib] + " "
    // + GLSimpleVertex.ATTRIBUTES_TYPE[nAttrib] + " stride = " +
    // GLSimpleVertex.VERTEX_BYTESIZE + " shift = " +
    // GLSimpleVertex.ATTRIBUTES_BYTEOFFSET[nAttrib]);
    // glEnableVertexAttribArray(GLSimpleVertex.ATTRIBUTES_ID[nAttrib]);
    //
    // }

    glBufferData(GL_ARRAY_BUFFER, this.getFlippedVerticesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedVerticesBuffer());

    // glBindBuffer(GL_ARRAY_BUFFER, 0);

    // create the index VBO
    this.vboIndicesId = glGenBuffers();
    if (this.vboIndicesId <= 0) {
        logger.error("VBO(Indices) ID is invalid " + this.vboIndicesId);
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.vboIndicesId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this.getFlippedIndicesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedIndicesBuffer());

    glBindVertexArray(0);

}

From source file:fr.ign.cogit.geoxygene.util.gl.GLGradientComplex.java

License:Open Source License

/**
 * Bind Buffers with gl Context//ww w .ja v a  2 s.co m
 */
private void generateVao() {
    // Create a new Vertex Array Object in memory and select it (bind)
    this.vaoId = GL30.glGenVertexArrays();
    if (this.vaoId <= 0) {
        logger.error("VAO ID is invalid " + this.vaoId);
    }
    glBindVertexArray(this.vaoId);

    // create the Vertex VBO
    this.vboVerticesId = glGenBuffers();
    if (this.vboVerticesId <= 0) {
        logger.error("VBO(Vertices) ID is invalid " + this.vboVerticesId);
    }
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vboVerticesId);

    int byteShift = 0;
    for (GLInput input : this.getInputs()) {
        GL20.glVertexAttribPointer(input.getLocation(), input.getComponentCount(), input.getGlType(),
                input.isNormalized(), this.getStride(), byteShift);
        byteShift += input.getComponentCount() * GLTools.sizeInBytes(input.getGlType());
        glEnableVertexAttribArray(input.getLocation());

    }

    glBufferData(GL_ARRAY_BUFFER, this.getFlippedVerticesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedVerticesBuffer());

    // glBindBuffer(GL_ARRAY_BUFFER, 0);

    // create the index VBO
    this.vboIndicesId = glGenBuffers();
    if (this.vboIndicesId <= 0) {
        logger.error("VBO(Indices) ID is invalid " + this.vboIndicesId);
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.vboIndicesId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this.getFlippedIndicesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedIndicesBuffer());

    glBindVertexArray(0);

}

From source file:gui.lwjgl.GUIElementLoader.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  . j  a v  a  2 s .c  om
 * @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.
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 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.
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

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

From source file:io.root.gfx.glutils.GL.java

License:Apache License

public static void glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride,
        Buffer buffer) {/*from www.  j a  v  a2s. c om*/
    if (buffer instanceof ByteBuffer) {
        if (type == GL_BYTE)
            GL20.glVertexAttribPointer(indx, size, false, normalized, stride, (ByteBuffer) buffer);
        else if (type == GL_UNSIGNED_BYTE)
            GL20.glVertexAttribPointer(indx, size, true, normalized, stride, (ByteBuffer) buffer);
        else if (type == GL_SHORT)
            GL20.glVertexAttribPointer(indx, size, false, normalized, stride,
                    ((ByteBuffer) buffer).asShortBuffer());
        else if (type == GL_UNSIGNED_SHORT)
            GL20.glVertexAttribPointer(indx, size, true, normalized, stride,
                    ((ByteBuffer) buffer).asShortBuffer());
        else if (type == GL_FLOAT)
            GL20.glVertexAttribPointer(indx, size, normalized, stride, ((ByteBuffer) buffer).asFloatBuffer());
        else
            throw new RootException("Can't use " + buffer.getClass().getName() + " with type " + type
                    + " with this method. Use ByteBuffer and one of GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT or GL_FLOAT for type. ");
    } else
        throw new RootException(
                "Can't use " + buffer.getClass().getName() + " with this method. Use ByteBuffer instead. ");
}