Example usage for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER

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

Introduction

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

Prototype

int GL_ARRAY_BUFFER

To view the source code for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER.

Click Source Link

Document

Accepted by the target parameters of BindBuffer, BufferData, BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData, GetBufferParameteriv, and GetBufferPointerv.

Usage

From source file:com.grillecube.client.renderer.gui.font.FontModel.java

public final void initialize() {

    if (this.hasState(STATE_INITIALIZED)) {
        return;/*from   w ww  .jav a2  s .co m*/
    }
    this.setState(STATE_INITIALIZED);

    this.vao = GLH.glhGenVAO();
    this.vbo = GLH.glhGenVBO();

    this.vao.bind();
    {
        this.vbo.bind(GL15.GL_ARRAY_BUFFER);

        this.vao.setAttribute(0, 3, GL11.GL_FLOAT, false, (3 + 2 + 4) * 4, 0);
        this.vao.setAttribute(1, 2, GL11.GL_FLOAT, false, (3 + 2 + 4) * 4, 3 * 4);
        this.vao.setAttribute(2, 4, GL11.GL_FLOAT, false, (3 + 2 + 4) * 4, (3 + 2) * 4);

        //         this.vbo.unbind(GL15.GL_ARRAY_BUFFER);

        this.vao.enableAttribute(0);
        this.vao.enableAttribute(1);
        this.vao.enableAttribute(2);
    }
    //      this.vao.unbind();
}

From source file:com.grillecube.client.renderer.gui.font.FontModel.java

/** update FontModel GLVertexBuffer vertices depending on 'this.text' */
private final void updateText() {
    float[] vertices = this.generateFontBuffer();

    if (!this.hasState(FontModel.STATE_INITIALIZED)) {
        this.initialize();
    }/*from   w  w w. j av a  2s.  c  o  m*/

    this.vbo.bind(GL15.GL_ARRAY_BUFFER);
    if (vertices != null) {
        this.vbo.bufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);
        this.vertexCount = vertices.length / 5;
    } else {
        this.vbo.bufferSize(GL15.GL_ARRAY_BUFFER, 0, GL15.GL_STATIC_DRAW);
        this.vertexCount = 0;
    }
    this.setState(FontModel.STATE_TEXT_UP_TO_DATE);
}

From source file:com.grillecube.client.renderer.MainRenderer.java

private void initialiseDefaultVAO() {
    GLH.glhCheckError("pre default vao");

    this.defaultVao = GLH.glhGenVAO();
    this.defaultVbo = GLH.glhGenVBO();

    this.defaultVao.bind();
    this.defaultVbo.bind(GL15.GL_ARRAY_BUFFER);
    this.defaultVao.enableAttribute(0);
    this.defaultVao.setAttribute(0, 1, GL11.GL_FLOAT, false, 0, 0);

    float[] points = { 0 };
    this.defaultVbo.bufferData(GL15.GL_ARRAY_BUFFER, points, GL15.GL_STATIC_DRAW);

    GLH.glhCheckError("post default vao");
}

From source file:com.grillecube.client.renderer.Mesh.java

/** initialize opengl stuff (vao, vbo) */
public void initialize() {

    if (this.isInitialized()) {
        Logger.get().log(Logger.Level.WARNING, "tried to initialized a mesh that was already initialized!!");
        return;//from  ww w.j  a v  a2  s.c om
    }

    this.vao = GLH.glhGenVAO();
    this.vbo = GLH.glhGenVBO();

    this.vao.bind();
    this.vbo.bind(GL15.GL_ARRAY_BUFFER);

    this.setAttributes(this.vao, this.vbo);

    // this.vbo.unbind(GL15.GL_ARRAY_BUFFER);
    // this.vao.unbind();
}

From source file:com.grillecube.client.renderer.Mesh.java

protected final void setVertices(ByteBuffer buffer, int bytesPerVertex) {
    if (buffer == null || buffer.capacity() == 0) {
        if (this.isInitialized()) {
            this.deinitialize();
        }/*from  ww w  .  j a  v  a2  s.  c  o  m*/
        return;
    }

    if (!this.isInitialized()) {
        this.initialize();
    }
    this.vertexCount = buffer.capacity() / bytesPerVertex;
    this.vbo.bind(GL15.GL_ARRAY_BUFFER);
    this.vbo.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
}

From source file:com.grillecube.client.renderer.particles.ParticleRenderer.java

@Override
public void initialize() {

    this.programBillboardedParticles = new ProgramParticleBillboarded();
    this.programCube = new ProgramParticleCube();

    // vao init//from w  w  w . jav  a  2 s.c om
    this.cubeMesh = new CubeMesh();
    this.cubeMesh.initialize();

    this.cubeMesh.bind();
    this.cubeInstancesVBO = GLH.glhGenVBO();
    this.cubeInstancesVBO.bind(GL15.GL_ARRAY_BUFFER);
    this.cubeInstancesVBO.bufferSize(GL15.GL_ARRAY_BUFFER, 0, GL15.GL_STREAM_DRAW);
    this.cubeMesh.setAttributesInstanced();
}

From source file:com.grillecube.client.renderer.particles.ParticleRenderer.java

/** render every cube particles */
public final void renderCubeParticles(CameraProjective camera, ArrayList<ParticleCube> particles) {
    if (particles.size() == 0) {
        return;/*from   w  w w.j a va2s  .co  m*/
    }

    // get the number of cube particle alive
    int cube_count = Maths.min(particles.size(), ParticleRenderer.MAX_CUBE_PARTICLES);

    if (cube_count == ParticleRenderer.MAX_CUBE_PARTICLES) {
        Logger.get().log(Logger.Level.WARNING, "Max number of cube particle reached! " + particles.size() + "/"
                + ParticleRenderer.MAX_CUBE_PARTICLES);
    }

    // create a buffer to hold them all
    ByteBuffer floats = BufferUtils.createByteBuffer(cube_count * CubeMesh.FLOATS_PER_CUBE_INSTANCE * 4);
    int cubesInBuffer = 0;
    for (int i = 0; i < cube_count; i++) {
        ParticleCube particle = particles.get(i);

        // if not in frustum, do not render it
        if (!camera.isBoxInFrustum(particle, particle)) {
            continue;
        }

        Matrix4f mat = particle.getTransfMatrix();
        Vector4f color = particle.getColor();
        float health = particle.getHealthRatio();

        floats.putFloat(mat.m00);
        floats.putFloat(mat.m01);
        floats.putFloat(mat.m02);
        floats.putFloat(mat.m03);

        floats.putFloat(mat.m10);
        floats.putFloat(mat.m11);
        floats.putFloat(mat.m12);
        floats.putFloat(mat.m13);

        floats.putFloat(mat.m20);
        floats.putFloat(mat.m21);
        floats.putFloat(mat.m22);
        floats.putFloat(mat.m23);

        floats.putFloat(mat.m30);
        floats.putFloat(mat.m31);
        floats.putFloat(mat.m32);
        floats.putFloat(mat.m33);

        floats.putFloat(color.x);
        floats.putFloat(color.y);
        floats.putFloat(color.z);
        floats.putFloat(color.w);

        floats.putFloat(health);

        ++cubesInBuffer;
    }
    floats.flip();
    this.cubeInstancesVBO.bind(GL15.GL_ARRAY_BUFFER);
    int buffersize = cubesInBuffer * CubeMesh.FLOATS_PER_CUBE_INSTANCE * 4;
    this.cubeInstancesVBO.bufferDataUpdate(GL15.GL_ARRAY_BUFFER, floats, buffersize);

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    this.programCube.useStart();
    this.programCube.loadGlobalUniforms(camera);

    this.cubeMesh.bind();
    this.cubeMesh.drawInstanced(cubesInBuffer);

    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:com.grillecube.client.renderer.sky.SkyRenderer.java

@Override
public void initialize() {
    this.programSky = new ProgramSky();

    this.vao = GLH.glhGenVAO();
    this.vbo = GLH.glhGenVBO();

    this.vao.bind();
    this.vbo.bind(GL15.GL_ARRAY_BUFFER);
    ByteBuffer floats = GLGeometry.generateSphere(SKYDOME_PRECISION, SKYDOME_SIZE);
    this.vbo.bufferData(GL15.GL_ARRAY_BUFFER, floats, GL15.GL_STATIC_DRAW);
    this.vao.setAttribute(0, 3, GL11.GL_FLOAT, false, 4 * 3, 0);
    this.vao.enableAttribute(0);

}

From source file:com.grillecube.engine.opengl.object.GLVertexArray.java

/** bind the given VertexBuffer and set the attribute in the VertexArray */
public void setAttribute(GLVertexBuffer vbo, int attributeID, int length, int type, boolean normalized,
        int stride, int offset) {
    vbo.bind(GL15.GL_ARRAY_BUFFER);
    this.setAttribute(attributeID, length, type, normalized, stride, offset);
    vbo.unbind(GL15.GL_ARRAY_BUFFER);/*from  ww  w  . jav  a  2 s .c o m*/
}

From source file:com.grillecube.engine.opengl.object.GLVertexArray.java

/** bind the given VertexBuffer and set the attribute in the VertexArray */
public void setAttribute(float[] floats, int attributeID, int length, int type, boolean normalized, int stride,
        int offset) {
    GLVertexBuffer vbo = GLH.glhGenVBO();
    vbo.bind(GL15.GL_ARRAY_BUFFER);
    vbo.bufferData(GL15.GL_ARRAY_BUFFER, floats, GL15.GL_STATIC_DRAW);
    this.setAttribute(attributeID, length, type, normalized, stride, offset);
    vbo.unbind(GL15.GL_ARRAY_BUFFER);//  ww  w  .j  av  a 2s . c  o  m
}