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.engine.renderer.world.particles.ParticleRenderer.java

/** create a new cube object */
private void initializeVAO() {
    this._vao_cube = GLH.glhGenVAO();
    this._vbo_cube = GLH.glhGenVBO();

    this._vao_cube.bind();

    this._vbo_cube.bind(GL15.GL_ARRAY_BUFFER);
    this._vbo_cube.bufferData(GL15.GL_ARRAY_BUFFER, Cube.makeWithTrianglesAndFaces(1), GL15.GL_STATIC_DRAW);
    this._vao_cube.setAttribute(this._vbo_cube, 0, 4, GL11.GL_FLOAT, false, 4 * 4, 0);

    this._vbo_cube_instances = GLH.glhGenVBO();
    this._vbo_cube_instances.bind(GL15.GL_ARRAY_BUFFER);
    this._vbo_cube_instances.bufferSize(GL15.GL_ARRAY_BUFFER, 0, GL15.GL_STREAM_DRAW);
    this._vao_cube.setAttributeInstanced(1, 4, GL11.GL_FLOAT, false, FLOATS_PER_CUBE_INSTANCE * 4, 0 * 4);
    this._vao_cube.setAttributeInstanced(2, 4, GL11.GL_FLOAT, false, FLOATS_PER_CUBE_INSTANCE * 4, 4 * 4);
    this._vao_cube.setAttributeInstanced(3, 4, GL11.GL_FLOAT, false, FLOATS_PER_CUBE_INSTANCE * 4, 8 * 4);
    this._vao_cube.setAttributeInstanced(4, 4, GL11.GL_FLOAT, false, FLOATS_PER_CUBE_INSTANCE * 4, 12 * 4);
    this._vao_cube.setAttributeInstanced(5, 4, GL11.GL_FLOAT, false, FLOATS_PER_CUBE_INSTANCE * 4, 16 * 4);
    this._vao_cube.setAttributeInstanced(6, 1, GL11.GL_FLOAT, false, FLOATS_PER_CUBE_INSTANCE * 4, 20 * 4);

    this._vao_cube.enableAttribute(0);
    this._vao_cube.enableAttribute(1);
    this._vao_cube.enableAttribute(2);
    this._vao_cube.enableAttribute(3);
    this._vao_cube.enableAttribute(4);
    this._vao_cube.enableAttribute(5);
    this._vao_cube.enableAttribute(6);
}

From source file:com.grillecube.engine.renderer.world.particles.ParticleRenderer.java

/** update the cube instances vbo data */
private void updateVBO(CameraProjectiveWorld camera) {

    if (this._cube_particles.size() == 0) {
        return;//from w w w. j a v  a  2s. com
    }

    // get the number of cube particle alive
    int cube_count = Maths.min(this._cube_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! "
                + this._cube_particles.size() + "/" + ParticleRenderer.MAX_CUBE_PARTICLES);
    }

    // create a buffer to hold them all
    FloatBuffer floats = BufferUtils.createFloatBuffer(cube_count * ParticleRenderer.FLOATS_PER_CUBE_INSTANCE);
    this._cubes_in_buffer = 0;
    for (int i = 0; i < cube_count; i++) {
        ParticleCube particle = this._cube_particles.get(i);

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

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

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

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

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

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

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

        floats.put(health);

        ++this._cubes_in_buffer;
    }

    floats.flip();
    this._vbo_cube_instances.bind(GL15.GL_ARRAY_BUFFER);
    int buffersize = this._cubes_in_buffer * FLOATS_PER_CUBE_INSTANCE * 4;
    this._vbo_cube_instances.bufferDataUpdate(GL15.GL_ARRAY_BUFFER, floats, buffersize);
}

From source file:com.grillecube.engine.renderer.world.sky.SkyRenderer.java

@Override
public void initialize() {

    this._sky_program = new ProgramSky();

    this._vao = GLH.glhGenVAO();
    this._vbo = GLH.glhGenVBO();

    this._vao.bind();
    this._vbo.bind(GL15.GL_ARRAY_BUFFER);
    FloatBuffer 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.renderer.world.terrain.TerrainMesh.java

/** initialize opengl stuff (vao, vbo) */
private void initializeMesh() {
    this._vao = GLH.glhGenVAO();
    this._vbo = GLH.glhGenVBO();

    this._vao.bind();
    this._vbo.bind(GL15.GL_ARRAY_BUFFER);

    int step = 4 * TerrainMesh.FLOAT_PER_VERTEX;
    this._vao.setAttribute(0, 3, GL11.GL_FLOAT, false, step, 0); // x, y, z
    this._vao.setAttribute(1, 3, GL11.GL_FLOAT, false, step, 3 * 4); // normal
    this._vao.setAttribute(2, 4, GL11.GL_FLOAT, false, step, (3 + 3) * 4); // tx
    this._vao.setAttribute(3, 1, GL11.GL_FLOAT, false, step, (3 + 3 + 4) * 4); // color
    this._vao.setAttribute(4, 1, GL11.GL_FLOAT, false, step, (3 + 3 + 4 + 1) * 4); // brightness

    this._vbo.unbind(GL15.GL_ARRAY_BUFFER);

    this._vao.enableAttribute(0);
    this._vao.enableAttribute(1);
    this._vao.enableAttribute(2);
    this._vao.enableAttribute(3);
    this._vao.enableAttribute(4);

    this._vao.unbind();

    this.setState(TerrainMesh.STATE_INITIALIZED);
}

From source file:com.grillecube.engine.renderer.world.terrain.TerrainMesh.java

/** called in the rendering thread */
public void render() {

    if (!this.hasState(TerrainMesh.STATE_VBO_UP_TO_DATE) && this._vertices != null
            && this._terrain.hasState(Terrain.STATE_VERTICES_UP_TO_DATE)) {

        if (!this.hasState(TerrainMesh.STATE_INITIALIZED)) {
            this.initializeMesh();
        }//from w  w w .  ja  va  2s .co m

        this.setState(TerrainMesh.STATE_VBO_UP_TO_DATE);
        this._vbo.bind(GL15.GL_ARRAY_BUFFER);
        this._vbo.bufferData(GL15.GL_ARRAY_BUFFER, this._vertices, GL15.GL_STATIC_DRAW);
        this._vertex_count = this._vertices.capacity() / TerrainMesh.FLOAT_PER_VERTEX;
        this._vertices = null; // no longerneed it
    }

    if (this._vertex_count <= 0) {
        return;
    }

    this._vao.bind();
    this._vao.draw(GL11.GL_TRIANGLES, 0, this._vertex_count);
}

From source file:com.mtbs3d.minecrift.MCOculus.java

License:LGPL

public void endFrame() {
    GL11.glDisable(GL11.GL_CULL_FACE); // Oculus wants CW orientations, avoid the problem by turning off culling...
    GL11.glDisable(GL11.GL_DEPTH_TEST); // Nothing is drawn with depth test on...

    // End the frame
    super.endFrame();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Unbind GL_ARRAY_BUFFER for my own vertex arrays to work...
    GL11.glEnable(GL11.GL_CULL_FACE); // Turn back on...
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Turn back on...
    GL11.glClearDepth(1); // Oculus set this to 0 (the near plane), return to normal...
    ARBShaderObjects.glUseProgramObjectARB(0); // Oculus shader is still active, turn it off...

    Display.processMessages();/*from   www  . java2 s .c  o  m*/
}

From source file:com.mtbs3d.minecrift.provider.MCOculus.java

License:LGPL

public void endFrame() {
    GL11.glDisable(GL11.GL_CULL_FACE); // Oculus wants CW orientations, avoid the problem by turning off culling...
    GL11.glDisable(GL11.GL_DEPTH_TEST); // Nothing is drawn with depth test on...
    //GL30.glBindVertexArray(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Unbind GL_ARRAY_BUFFER for my own vertex arrays to work...
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    // End the frame
    super.endFrame();

    GL11.glFrontFace(GL11.GL_CCW); // Needed for OVR SDK 0.4.0
    GL11.glEnable(GL11.GL_CULL_FACE); // Turn back on...
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Turn back on...
    GL11.glClearDepth(1); // Oculus set this to 0 (the near plane), return to normal...
    ARBShaderObjects.glUseProgramObjectARB(0); // Oculus shader is still active, turn it off...

    Display.processMessages();//from   w  w  w .j  ava 2 s .  c o m
}

From source file:com.opengrave.og.base.Renderable2D.java

License:Open Source License

@Override
public void dealWithChange() {
    Util.checkErr();/*  w  w w.j  a  v a 2s.c o m*/
    if (vaoID == 0) {
        vaoID = GL30.glGenVertexArrays();
    }
    GL30.glBindVertexArray(vaoID);
    Util.checkErr();
    if (vbopID == 0) {
        vbopID = GL15.glGenBuffers();
    }
    Util.checkErr();
    if (vbocID == 0) {
        vbocID = GL15.glGenBuffers();
    }
    Util.checkErr();
    if (vbotID == 0) {
        vbotID = GL15.glGenBuffers();
    }
    Util.checkErr();
    if (changed) {
        changed = false;
        vertexList.clear();
        posBuffer.clear();
        colBuffer.clear();
        texBuffer.clear();
        recreate();
        Util.checkErr();
        int verts = vertexList.size();
        if (vertexList.size() == 0) {
            return;
        }
        if (posBuffer.capacity() != verts * 2) {
            posBuffer = BufferUtils.createFloatBuffer(verts * 2);
        }
        Util.checkErr();
        if (colBuffer.capacity() != verts * 4) {
            colBuffer = BufferUtils.createFloatBuffer(verts * 4);
        }
        if (texBuffer.capacity() != verts * 3) {
            texBuffer = BufferUtils.createFloatBuffer(verts * 3);
        }
        for (Vertex2D v2 : vertexList) {
            posBuffer.put(v2.x).put(v2.y);
            texBuffer.put(v2.tx).put(v2.ty).put(v2.tz);
            colBuffer.put(v2.r).put(v2.g).put(v2.b).put(v2.a);
        }
        posBuffer.flip();
        texBuffer.flip();
        colBuffer.flip();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbopID);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, posBuffer, GL15.GL_STREAM_DRAW);
        GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 0, 0);
        Util.checkErr();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbocID);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colBuffer, GL15.GL_STREAM_DRAW);
        GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, 0, 0);
        Util.checkErr();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbotID);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, texBuffer, GL15.GL_STREAM_DRAW);
        GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 0, 0);
        Util.checkErr();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    }
}

From source file:com.opengrave.og.base.Renderable2D.java

License:Open Source License

@Override
public void renderForPicking(Matrix4f matrix, Pickable object) {
    dealWithChange();/*  w w w.  j a  v  a  2  s .co  m*/
    if (vertexList.size() == 0) {
        return;
    }
    int pID = Resources.loadShader("pickinggui.vs", "pickinggui.fs").getProgram();
    GL20.glUseProgram(pID);
    GL30.glBindVertexArray(vaoID);
    GL20.glEnableVertexAttribArray(0);
    Util.setMatrices(pID, location2d);
    Picking.registerObject(pID, getContext(), object);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexList.size());
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
}

From source file:com.opengrave.og.base.Renderable2D.java

License:Open Source License

@Override
public void render(Matrix4f matrix, RenderStyle style) {
    Util.checkErr();//from  w w w . j a v  a 2 s  .c  om
    dealWithChange();
    Util.checkErr();
    if (vertexList.size() == 0) {
        return;
    }
    int pID = Resources.loadShader("gui.vs", "gui.fs").getProgram();
    GL20.glUseProgram(pID);
    GL30.glBindVertexArray(vaoID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    Util.checkErr();
    if (texture != null) {
        texture.bind(GL13.GL_TEXTURE0);
    }
    Util.setMatrices(pID, location2d);
    Util.checkErr();

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexList.size());
    Util.checkErr();
    if (texture != null) {
        texture.unbind();
    }
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    Util.checkErr();

    GL30.glBindVertexArray(0);
    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    Util.checkErr();
}