Example usage for org.lwjgl.opengl GL30 glBindVertexArray

List of usage examples for org.lwjgl.opengl GL30 glBindVertexArray

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL30 glBindVertexArray.

Prototype

public static void glBindVertexArray(@NativeType("GLuint") int array) 

Source Link

Document

Binds a vertex array object

Usage

From source file:de.ikosa.mars.viewer.glviewer.GLHeightMapMesh.java

License:Open Source License

public void use() {
    GL30.glBindVertexArray(vertexArrayObjectId);

    GL20.glEnableVertexAttribArray(0);//from w  w w .  ja v  a2s  .  c om

    GL20.glEnableVertexAttribArray(1);

    GL20.glEnableVertexAttribArray(2);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexVboId);

}

From source file:de.ikosa.mars.viewer.glviewer.GLHeightMapMeshBuilder.java

License:Open Source License

public GLHeightMapMesh createMesh() {
    ML.d(String.format("Writing mesh \"%s\" to buffer...", name));
    // create VBO buffers
    FloatBuffer interleavedBuffer = BufferUtils.createFloatBuffer(matrixSizeX * matrixSizeY * 9);
    int stride = 12 + 12 + 12;
    int normalPosition = 12;
    int texCoordPosition = 24;

    // fill buffers
    for (int y = 0; y < matrixSizeY; y++) {
        for (int x = 0; x < matrixSizeX; x++) {
            GLWorldVertex vertex = vMatrix[x][y];
            interleavedBuffer.put(vertex.px);
            interleavedBuffer.put(vertex.py);
            interleavedBuffer.put(vertex.pz);
            interleavedBuffer.put(vertex.nx);
            interleavedBuffer.put(vertex.ny);
            interleavedBuffer.put(vertex.nz);
            interleavedBuffer.put(vertex.tu);
            interleavedBuffer.put(vertex.tv);
            interleavedBuffer.put(vertex.tw);
        }/* ww w .  jav a2 s  .  c  o m*/
    }

    interleavedBuffer.flip();

    ML.d("Done.");

    // create VAO
    int vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    // create VBOs
    int interleavedVboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, interleavedVboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, interleavedBuffer, GL15.GL_STATIC_DRAW);

    // attribs
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, stride, 0);
    GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, stride, normalPosition);
    GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, stride, texCoordPosition);

    // unbind buffers
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);

    // create index buffer
    iBuffer.flip();

    int indexVboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexVboId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, iBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    GLTextureArray terrainTexture = (GLTextureArray) GLResources.global.getTexture("terrain");

    // create mesh object
    GLHeightMapMesh mesh = new GLHeightMapMesh(name, vaoId, interleavedVboId, indexVboId, indices,
            terrainTexture);
    return mesh;
}

From source file:engine.render.TexturedQuad.java

private void setupQuad(Vector2f size) {
    TexturedVertex v0 = new TexturedVertex();
    v0.setXYZ(-0.5f * size.x, 0.5f * size.y, 0);
    v0.setRGB(1, 0, 0);/*from  w  ww .  j av  a  2s . c  o  m*/
    v0.setST(0, 0);
    TexturedVertex v1 = new TexturedVertex();
    v1.setXYZ(-0.5f * size.x, -0.5f * size.x, 0);
    v1.setRGB(0, 1, 0);
    v1.setST(0, 1);
    TexturedVertex v2 = new TexturedVertex();
    v2.setXYZ(0.5f * size.y, -0.5f * size.x, 0);
    v2.setRGB(0, 0, 1);
    v2.setST(1, 1);
    TexturedVertex v3 = new TexturedVertex();
    v3.setXYZ(0.5f * size.x, 0.5f * size.y, 0);
    v3.setRGB(1, 1, 1);
    v3.setST(1, 0);

    TexturedVertex[] vertices = new TexturedVertex[] { v0, v1, v2, v3 };

    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length * TexturedVertex.elementCount);
    for (int i = 0; i < vertices.length; i++) {

        verticesBuffer.put(vertices[i].getElements());
    }
    verticesBuffer.flip();

    byte[] indices = { 0, 1, 2, 2, 3, 0 };
    indicesCount = indices.length;
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
    indicesBuffer.put(indices);
    indicesBuffer.flip();

    vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);

    GL20.glVertexAttribPointer(0, TexturedVertex.positionElementCount, GL11.GL_FLOAT, false,
            TexturedVertex.stride, TexturedVertex.positionByteOffset);

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

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

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL30.glBindVertexArray(0);

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

    //this.exitOnGLError("setupQuad");
}

From source file:engine.render.TexturedQuad.java

public void renderQuad() {

    int shaderID = shader.getProgramID();
    GL20.glUseProgram(shaderID);/*from   w  ww  . j  a v a2s  . c o m*/
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());

    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
    glUniform2f(glGetUniformLocation(shaderID, "scale"), scale.x, scale.y);
    glUniform2f(glGetUniformLocation(shaderID, "translation"), translation.x, translation.y);
    glUniform2f(glGetUniformLocation(shaderID, "cameraOffset"), cameraOffset.x, cameraOffset.y);
    glUniform1f(glGetUniformLocation(shaderID, "rotation"), rotation);
    glUniform2f(glGetUniformLocation(shaderID, "resolution"), resolution.x, resolution.y);

    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
    glDisable(GL_BLEND);
    GL20.glUseProgram(0);
}

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);/*www. jav a  2  s  .c om*/

        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.ChunkVAO.java

License:Open Source License

public void render(final boolean solid) {

    try {/*ww  w .  j a v  a  2  s . c  om*/
        if (solid) {
            if (holdsSolid) {
                GL30.glBindVertexArray(this.vao_handle_solid);
                if (Veya.wireframeSwitch) {
                    GL11.glDrawElements(GL11.GL_LINE_STRIP, this.index_length_solid, GL11.GL_UNSIGNED_INT, 0);
                } else {
                    GL11.glDrawElements(GL11.GL_TRIANGLE_STRIP, this.index_length_solid, GL11.GL_UNSIGNED_INT,
                            0);
                }
                GL30.glBindVertexArray(0);
            }
        } else {
            if (holdsTransparent) {
                GL30.glBindVertexArray(this.vao_handle_transparent);
                if (Veya.wireframeSwitch) {
                    GL11.glDrawElements(GL11.GL_LINE_STRIP, this.index_length_transparent, GL11.GL_UNSIGNED_INT,
                            0);
                } else {
                    GL11.glDrawElements(GL11.GL_TRIANGLE_STRIP, this.index_length_transparent,
                            GL11.GL_UNSIGNED_INT, 0);
                }
                GL30.glBindVertexArray(0);
            }
        }
    } catch (final OpenGLException e) {
        System.out.println("vao_handle_solid: " + this.vao_handle_solid);
        e.printStackTrace();
    }

}

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 ww  .  j  a v  a 2s  . co  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

public static void draw() {
    GraphicMotor.checkInstance();//from  www .j a  v a 2 s  .co  m

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL20.glUseProgram(instance.shipShaderId);

    GL20.glUniform1i(instance.useTextureLocation, instance.drawPolygonFrame ? 0 : 1);
    int drawStyle = instance.drawPolygonFrame ? GL11.GL_LINE_LOOP : GL11.GL_TRIANGLES;

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, instance.shipTextureId);
    GL30.glBindVertexArray(instance.shipVaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    GL20.glEnableVertexAttribArray(3);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, instance.shipVboiId);
    GL11.glDrawElements(drawStyle, instance.shipVboiLenght, GL11.GL_UNSIGNED_INT, 0);

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL20.glDisableVertexAttribArray(3);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    GL20.glUseProgram(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();/*from w  w  w  .  ja v a 2s  .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.render.DisplayableRenderer.java

License:Open Source License

private static boolean rendercomplex(GLComplex c, GLProgram program, AffineTransform modelToViewTransform)
        throws GLException {
    boolean success = true;
    double m00 = modelToViewTransform.getScaleX();
    double m02 = modelToViewTransform.getTranslateX() + c.getMinX() * modelToViewTransform.getScaleX();
    double m11 = modelToViewTransform.getScaleY();
    double m12 = modelToViewTransform.getTranslateY() + c.getMinY() * modelToViewTransform.getScaleY();
    //        success &= GLTools.glCheckError("GL4FeatureRenderer::setGLViewMatrix()");
    program.setUniform(GeoxygeneConstants.GL_VarName_M00ModelToViewMatrix, m00);
    program.setUniform(GeoxygeneConstants.GL_VarName_M02ModelToViewMatrix, m02);
    program.setUniform(GeoxygeneConstants.GL_VarName_M11ModelToViewMatrix, m11);
    program.setUniform(GeoxygeneConstants.GL_VarName_M12ModelToViewMatrix, m12);
    GL30.glBindVertexArray(c.getVaoId());
    //        success &= GLTools.glCheckError("direct rendering binding vaoId = " + c.getVaoId());
    DisplayableRenderer.drawComplex(c);/*from   w w  w .  j a  v  a 2  s. c  om*/
    //        success &= GLTools.glCheckError("direct rendering drawing GLSimpleComplex class = " + c.getClass().getSimpleName());
    GL30.glBindVertexArray(0);
    success &= GLTools.glCheckError("exiting direct rendering");
    return success;
}