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:com.flowpowered.caustic.lwjgl.gl30.GL30VertexArray.java

License:MIT License

@Override
public void draw() {
    checkCreated();/*from  w  w w .  j a  va  2s  .c o m*/
    // Bind the vao
    GL30.glBindVertexArray(id);
    // Bind the index buffer
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBufferID);
    // Set the polygon mode
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, polygonMode.getGLConstant());
    // Draw all indices with the provided mode
    GL11.glDrawElements(drawingMode.getGLConstant(), indicesDrawCount, GL11.GL_UNSIGNED_INT,
            indicesOffset * DataType.INT.getByteSize());
    // Unbind the index buffer
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    // Unbind the vao
    GL30.glBindVertexArray(0);
    // Check for errors
    LWJGLUtil.checkForGLError();
}

From source file:com.geekyaubergine.geekyjgameutil.model.ModelLoader.java

License:Open Source License

/**
 * Creates VAO and returns its ID/*from w ww .  j a v a 2  s . com*/
 * @return Created VAO ID
 */
private static int createVAO() {
    int vaoId = GL30.glGenVertexArrays();
    vaos.add(vaoId);
    GL30.glBindVertexArray(vaoId);
    return vaoId;
}

From source file:com.geekyaubergine.geekyjgameutil.model.ModelLoader.java

License:Open Source License

/**
 * Unbinds current VAO
 */
private static void unbindVAO() {
    GL30.glBindVertexArray(0);
}

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

protected void createVBO() {
    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length * Vertex.elementCount);
    for (int i = 0; i < vertices.length; i++) {
        verticesBuffer.put(vertices[i].getElements());
    }//from   w w  w. j  ava 2 s  .  c om
    verticesBuffer.flip();

    // Create the indices buffer and place the data in it.
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesData.length);
    indicesBuffer.put(indicesData);
    indicesBuffer.flip();

    // Initialize the VAO 
    vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    // Initialize the VBO 
    vboVerticesId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVerticesId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);

    // Put the positions in attribute list 0
    GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride,
            Vertex.positionByteOffset);
    // Put the color components in attribute list 1
    GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride,
            Vertex.colorByteOffset);
    // Put the texture coordinates in attribute list 2
    GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride,
            Vertex.textureByteOffset);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    // Deselect the VAO
    GL30.glBindVertexArray(0);

    // Create a VBO for the indices.
    vboIndicesId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboIndicesId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

/**
 * Render the Object.//from  w ww.  j a va 2s.  co  m
 */
public void render() {
    FloatBuffer matrix44Buffer = BufferUtils.createFloatBuffer(16);
    modelMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(ShaderProgram.getMML(), false, matrix44Buffer);

    // 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 quad 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, vboIndicesId);

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

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

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

public void destroy() {
    // Disable the VBO index from the VAO attributes list
    GL20.glDisableVertexAttribArray(0);//from w  w  w . j  av  a 2s . c  o  m

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

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboIndicesId);

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

From source file:com.google.gapid.glviewer.GeometryScene.java

License:Apache License

@Override
public void init(Renderer renderer) {
    float[] background = new float[] { .2f, .2f, .2f, 1f };

    LOG.log(FINE, "GL Version:   " + GL11.glGetString(GL11.GL_VERSION));
    LOG.log(FINE, "GLSL Version: " + GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));

    shaders = Shaders.init(renderer);//from   www .j ava  2s.  c o  m
    if (renderable != null) {
        renderable.init(renderer);
    }

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glClearColor(background[0], background[1], background[2], background[3]);
    GL11.glPointSize(4);
    GL30.glBindVertexArray(GL30.glGenVertexArrays());
}

From source file:com.google.gapid.glviewer.gl.Renderer.java

License:Apache License

/**
 * Initializes the renderer for use./*from  w ww  .ja  v a2  s.  c o  m*/
 * Must be called before any other methods.
 */
public void initialize() {
    GL30.glBindVertexArray(GL30.glGenVertexArrays());
    buildPrimitives();
}

From source file:com.google.gapid.glviewer.Viewer.java

License:Apache License

@Override
public void init() {
    float[] background = new float[] { .2f, .2f, .2f, 1f };

    LOG.log(FINE, "GL Version:   " + GL11.glGetString(GL11.GL_VERSION));
    LOG.log(FINE, "GLSL Version: " + GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));

    shaders = Shaders.init();/* w w  w .  jav  a  2s  . c o  m*/
    if (renderable != null) {
        renderable.init();
    }

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glClearColor(background[0], background[1], background[2], background[3]);
    GL11.glPointSize(4);
    GL30.glBindVertexArray(GL30.glGenVertexArrays());
}

From source file:com.grillecube.client.opengl.GLVertexArray.java

/** bind the vao */
public void bind() {
    GL30.glBindVertexArray(this._id);
}