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:kubex.gui.FinalDrawManager.java

License:Creative Commons License

public FinalDrawManager(World world, Sky sky, ShadowsManager shadowsManager, LiquidRenderer liquidRenderer,
        Matrix4f projCameraInverseMatrix, float cnear, float cfar) {
    this.world = world;
    this.sky = sky;
    this.shadowsManager = shadowsManager;
    this.liquidRenderer = liquidRenderer;
    this.cnear = cnear;
    this.cfar = cfar;

    this.finalDrawVbo = glGenBuffers();
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.finalDrawVbo);
    glBufferData(GL15.GL_ARRAY_BUFFER, (vboContent.length * 4), GL15.GL_DYNAMIC_DRAW);
    glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    //On initcialization, performs the correspondent opperations to find the camera position far plane frustrum points multiplying them by the inverse projection matrix, constant in all execution
    Matrix4f.transform(projCameraInverseMatrix, xpypProjection, xpyp);
    Matrix4f.transform(projCameraInverseMatrix, xmypProjection, xmyp);
    Matrix4f.transform(projCameraInverseMatrix, xpymProjection, xpym);
    Matrix4f.transform(projCameraInverseMatrix, xmymProjection, xmym);

    vboContent[5] = xmym.x / xmym.w;/*from  www. j av  a  2  s  .c  om*/
    vboContent[6] = xmym.y / xmym.w;
    vboContent[7] = xmym.z / xmym.w;
    vboContent[13] = xpym.x / xpym.w;
    vboContent[14] = xpym.y / xpym.w;
    vboContent[15] = xpym.z / xpym.w;
    vboContent[21] = xpyp.x / xpyp.w;
    vboContent[22] = xpyp.y / xpyp.w;
    vboContent[23] = xpyp.z / xpyp.w;
    vboContent[29] = xmym.x / xmym.w;
    vboContent[30] = xmym.y / xmym.w;
    vboContent[31] = xmym.z / xmym.w;
    vboContent[37] = xpyp.x / xpyp.w;
    vboContent[38] = xpyp.y / xpyp.w;
    vboContent[39] = xpyp.z / xpyp.w;
    vboContent[45] = xmyp.x / xmyp.w;
    vboContent[46] = xmyp.y / xmyp.w;
    vboContent[47] = xmyp.z / xmyp.w;
}

From source file:kubex.gui.FinalDrawManager.java

License:Creative Commons License

/**
 * Renders all the specified deferred passes. If the last fbo proportioned is 0, it will draw to the screen at the end.
 *//*w  w w . j  a v a2  s .  c o  m*/
public final void draw(DeferredShaderProgram[] programs, int[] fbos, Matrix4f projWorldInverseMatrix,
        Matrix4f viewMatrix, Matrix4f projectionMatrix, float xres, float yres) {
    //Calculates the world space points of the far plane frustrum.
    Matrix4f.transform(projWorldInverseMatrix, xpypProjection, xpyp);
    Matrix4f.transform(projWorldInverseMatrix, xmypProjection, xmyp);
    Matrix4f.transform(projWorldInverseMatrix, xpymProjection, xpym);
    Matrix4f.transform(projWorldInverseMatrix, xmymProjection, xmym);

    vboContent[2] = xmym.x / xmym.w;
    vboContent[3] = xmym.y / xmym.w;
    vboContent[4] = xmym.z / xmym.w;
    vboContent[10] = xpym.x / xpym.w;
    vboContent[11] = xpym.y / xpym.w;
    vboContent[12] = xpym.z / xpym.w;
    vboContent[18] = xpyp.x / xpyp.w;
    vboContent[19] = xpyp.y / xpyp.w;
    vboContent[20] = xpyp.z / xpyp.w;
    vboContent[26] = xmym.x / xmym.w;
    vboContent[27] = xmym.y / xmym.w;
    vboContent[28] = xmym.z / xmym.w;
    vboContent[34] = xpyp.x / xpyp.w;
    vboContent[35] = xpyp.y / xpyp.w;
    vboContent[36] = xpyp.z / xpyp.w;
    vboContent[42] = xmyp.x / xmyp.w;
    vboContent[43] = xmyp.y / xmyp.w;
    vboContent[44] = xmyp.z / xmyp.w;

    //Those arguments will be placed on the drawed quad via GPU vertex parameters.
    this.vbobuffer.put(vboContent);
    this.vbobuffer.flip();

    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.finalDrawVbo);
    glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, this.vbobuffer);

    this.vbobuffer.clear();

    //Draws each specified deferred shading rendering pass
    for (int i = 0; i < programs.length; i++) {
        glBindFramebuffer(GL_FRAMEBUFFER, fbos[i]);
        programs[i].enable();
        programs[i].setupAttributes();
        uploadToShader(programs[i], viewMatrix, projectionMatrix, xres, yres); //Uploads all needed uniforms to the current shader

        glDrawArrays(GL_TRIANGLES, 0, 6);

        programs[i].disable();
    }

    glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:kubex.gui.Hud.java

License:Creative Commons License

public Hud(HudShaderProgram hsp, int xres, int yres) {
    this.HSP = hsp;
    this.vbo = glGenBuffers();
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);

    HSP.enable();//ww w  .ja  v a 2s.  com
    HSP.setupAttributes();
    FloatBuffer toUpload = FloatBufferPool.getBuffer();
    float normx = CURSOR_SIZE / xres;
    float normy = CURSOR_SIZE / yres;

    float[] list = new float[CURSOR_VERT_NUM * 3 * 6];
    insertCircle(0, 0, normx, normy, CURSOR_VERT_NUM, CURSOR_R, CURSOR_G, CURSOR_B, CURSOR_ALPHA, list);

    toUpload.put(list);
    toUpload.flip();
    glBufferData(GL15.GL_ARRAY_BUFFER, (list.length * 4) + (36 * 4), GL15.GL_STATIC_DRAW);
    glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, toUpload);
    glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    FloatBufferPool.recycleBuffer(toUpload);
    this.currentVert = CURSOR_VERT_NUM * 3;
}

From source file:kubex.gui.Hud.java

License:Creative Commons License

/**
 * Draws the circle/*from   w  w w.j a v a 2s . c  o  m*/
 */
public void draw() {
    glEnable(GL11.GL_BLEND);
    glDisable(GL11.GL_DEPTH_TEST);
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    HSP.setupAttributes();
    glDrawArrays(GL_TRIANGLES, 0, currentVert);
    glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

private void SetupEntity(Vector3f[] vertex, Vector3f[] color, Vector2f[] uv) {

    // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class
    vertices = new VertexData[vertex.length];

    for (int i = 0; i < vertex.length; i++) {
        vertices[i] = new VertexData();
        vertices[i].setXYZ(vertex[i].x, vertex[i].y, vertex[i].z);
        vertices[i].setRGBA(color[i].x, color[i].y, color[i].z, 1.0f);
        vertices[i].setST(uv[i].x, uv[i].y);
    }//  w  w  w. j  a  v a2s. c o  m

    // Put each 'Vertex' in one FloatBuffer
    verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * VertexData.stride);
    FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer();
    for (int i = 0; i < vertices.length; i++) {
        // Add position, color and texture floats to the buffer
        verticesFloatBuffer.put(vertices[i].getElements());
    }
    verticesFloatBuffer.flip();

    // OpenGL expects to draw vertices in counter clockwise order by default
    // TODO: Move this to Setup.
    byte[] indices = { 0, 1, 2, 2, 3, 0 };

    indicesCount = indices.length;
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
    indicesBuffer.put(indices);
    indicesBuffer.flip();

    // Create a new Vertex Array Object in memory and select it (bind)
    vaoId = GL30.glGenVertexArrays();
    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, VertexData.positionElementCount, GL11.GL_FLOAT, false, VertexData.stride,
            VertexData.positionByteOffset);
    // Put the color components in attribute list 1
    GL20.glVertexAttribPointer(1, VertexData.colorElementCount, GL11.GL_FLOAT, false, VertexData.stride,
            VertexData.colorByteOffset);
    // Put the texture coordinates in attribute list 2
    GL20.glVertexAttribPointer(2, VertexData.textureElementCount, GL11.GL_FLOAT, false, VertexData.stride,
            VertexData.textureByteOffset);

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

    Game.cameraPos = new Vector3f(0, 0, -1);

    Game.exitOnGLError("setupQuad");
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

@Override
public void Render(float interpolation) {

    GL20.glUseProgram(pId);//from   w  w  w. ja v a  2  s .  com

    // Bind the texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // Bind to the VAO that has all the information about the vertices
    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    // Bind to the index VBO that has all the information about the order of the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);

    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);

    GL20.glUseProgram(0);

    Game.exitOnGLError("renderCycle");
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

public void destroy() {
    // Delete the Program
    GL20.glUseProgram(0);//from  w w  w.  j  a  v a 2  s. com
    GL20.glDeleteProgram(pId);

    // Select the VAO
    GL30.glBindVertexArray(vaoId);

    // Disable the VBO index from the VAO attributes list
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);

    // Delete the vertex VBO
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboId);

    // Delete the index VBO
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboiId);

    // Delete the VAO
    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(vaoId);
}

From source file:main.Loader.java

private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) {
    int vboID = GL15.glGenBuffers();
    vbos.add(vboID);/*from   w  w w .j a  v  a  2  s  .  co m*/
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
    FloatBuffer buffer = storeDataInFloatBuffer(data);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

public void resizeBuffer() {
    vertByteBuff = BufferUtils.createByteBuffer(vertexCount * Vertex.stride);
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
    FloatBuffer vertFloatBuff = vertByteBuff.asFloatBuffer();
    for (Drawable object : objects) {
        object.store(vertFloatBuff);// www . j a v  a  2s .  co m
        indicesBuffer.put(object.getIndices());
    }
    for (Drawable object : orthoObjects) {
        object.store(vertFloatBuff);
        indicesBuffer.put(object.getIndices());
    }
    indicesBuffer.flip();
    vertFloatBuff.flip();
    GL30.glBindVertexArray(vaoId);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertFloatBuff, GL15.GL_STREAM_DRAW);
    GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, Vertex.stride, 0);
    GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, Vertex.stride, 16);
    GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, Vertex.stride, 32);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);

    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:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

private synchronized void logic() {
    if (invalidated) {
        invalidated = false;/*from w ww  .  j a  va  2s . c o m*/
        resizeBuffer();
    }
    mvpMat = cam.getMVP();
    if (vertexCount == 0)
        return;
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    int offset = 0;
    FloatBuffer vertFloatBuff = vertByteBuff.asFloatBuffer();
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, offset, vertByteBuff);
    vertFloatBuff.rewind();
    for (Drawable object : objects) {
        object.store(vertFloatBuff);
    }
    for (Drawable object : orthoObjects) {
        object.store(vertFloatBuff);
    }
    vertFloatBuff.flip();
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, offset, vertByteBuff);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    // GL20.glUseProgram(shader.getPID());
    // mvpMat.get(0, matBuff);
    // // matBuff.flip();
    // // matBuff.put(0,5.0f);
    // GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff);
    // GL20.glUseProgram(0);
}