Example usage for org.lwjgl.opengl GL15 glBufferData

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

Introduction

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

Prototype

public static void glBufferData(@NativeType("GLenum") int target, @NativeType("void const *") double[] data,
        @NativeType("GLenum") int usage) 

Source Link

Document

Array version of: #glBufferData BufferData

Usage

From source file:net.neilcsmith.praxis.video.opengl.internal.VertexBufferObject.java

License:Apache License

/** {@inheritDoc} */
public void setVertices(float[] vertices, int offset, int count) {
    isDirty = true;/* w  ww.j  ava2 s . c om*/
    if (isDirect) {
        //            BufferUtils.copy(vertices, byteBuffer, count, offset);
        buffer.clear();
        buffer.put(vertices, offset, count);
        buffer.position(0);
        buffer.limit(count);
    } else {
        buffer.clear();
        buffer.put(vertices, offset, count);
        buffer.flip();
        byteBuffer.position(0);
        byteBuffer.limit(buffer.limit() << 2);
    }

    if (isBound) {
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, byteBuffer, usage);
        isDirty = false;
    }
}

From source file:net.neilcsmith.praxis.video.opengl.internal.VertexBufferObject.java

License:Apache License

/** Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements
 * /*from   w ww. j a  va2 s  . c om*/
 * @param shader the shader */
public void bind(ShaderProgram shader) {

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferHandle);
    if (isDirty) {
        byteBuffer.limit(buffer.limit() * 4);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, byteBuffer, usage);
        isDirty = false;
    }

    int numAttributes = attributes.size();
    for (int i = 0; i < numAttributes; i++) {
        VertexAttribute attribute = attributes.get(i);
        shader.enableVertexAttribute(attribute.alias);
        int colorType = GL11.GL_FLOAT;
        boolean normalize = false;
        if (attribute.usage == VertexAttributes.Usage.ColorPacked) {
            colorType = GL11.GL_UNSIGNED_BYTE;
            normalize = true;
        }
        shader.setVertexAttribute(attribute.alias, attribute.numComponents, colorType, normalize,
                attributes.vertexSize, attribute.offset);
    }
    isBound = true;
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java

License:Apache License

public void setBufferData(int vboID, ByteBuffer byteBuffer, int usage) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, byteBuffer, usage);
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java

License:Apache License

public void setBufferData(int vboID, FloatBuffer floatBuffer, int usage) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, floatBuffer, usage);
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java

License:Apache License

public void setBufferData(int vboID, IntBuffer intBuffer, int usage) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, intBuffer, usage);
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java

License:Apache License

public void setBufferData(int vboID, ShortBuffer shortBuffer, int usage) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, shortBuffer, usage);
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java

License:Apache License

public void setBufferElementData(int vboID, ByteBuffer byteBuffer, int usage) {
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, byteBuffer, usage);
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java

License:Apache License

public void setBufferElementData(int vboID, IntBuffer intBuffer, int usage) {
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, intBuffer, usage);
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java

License:Apache License

public void setBufferElementData(int vboID, ShortBuffer shortBuffer, int usage) {
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, shortBuffer, usage);
}

From source file:opengl.test.object.CaroTable.java

@Override
protected void initVertex() {
    GL30.glBindVertexArray(vao);//bind vao  

    // position        color       texCoord

    float[] data = new float[] { -0.5f, -0.5f, 0f, 1f, 1f, 1f, 0f, 0f, 0.5f, -0.5f, 0f, 1f, 1f, 1f, 1f, 0f,
            -0.5f, 0.5f, 0f, 1f, 1f, 1f, 0f, 1f, 0.5f, 0.5f, 0f, 1f, 1f, 1f, 1f, 1f };

    dataBuffer = BufferUtils.createFloatBuffer(data.length);
    dataBuffer.put(data);/* w  w w  .j  av a  2s  .com*/
    dataBuffer.flip();
    Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity  : " + dataBuffer.capacity());

    this.vbo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, dataBuffer, GL15.GL_STATIC_DRAW);

    this.VertexAttribPointer();

    int[] indices = { 0, 1, 2, 2, 1, 3 };
    IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indices.length);
    indicesBuffer.put(indices);
    indicesBuffer.flip();
    this.ebo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_DYNAMIC_DRAW);

    IntBuffer w = BufferUtils.createIntBuffer(1);
    IntBuffer h = BufferUtils.createIntBuffer(1);
    IntBuffer comp = BufferUtils.createIntBuffer(1);
    STBImage.stbi_set_flip_vertically_on_load(1);
    ByteBuffer image = STBImage.stbi_load("resource/3x3grid.png", w, h, comp, 0);

    int weight = w.get(0);
    int height = h.get(0);
    int compe = comp.get(0);

    Logger.getGlobal().log(Level.FINEST,
            "STBImage load status : " + weight + " " + height + " " + compe + " " + image);

    textureID = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

    GL30.glBindVertexArray(0);//unbind vao
}