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:bd.ac.seu.lwjgldemo.Renderer.java

private void setupModel() {
    int COLUMNS_PER_ROW = 3;
    vertices = new double[NUM_VERTICES * COLUMNS_PER_ROW];
    for (int row = 0; row < vertices.length / COLUMNS_PER_ROW; row++) {
        vertices[row * COLUMNS_PER_ROW + 0] = Math.random();
        vertices[row * COLUMNS_PER_ROW + 1] = Math.random();
        vertices[row * COLUMNS_PER_ROW + 2] = 0;
    }//  w w  w .j a  va 2s.  co m

    DoubleBuffer buffer = BufferUtils.createDoubleBuffer(vertices.length);
    buffer.put(vertices);
    buffer.flip();

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

    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(0, 3, GL11.GL_DOUBLE, false, 0, 0);

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

From source file:bd.ac.seu.lwjgldemo.Renderer.java

private void drawSomething() {
    GL11.glClearColor(0, 0, 0, 1);/*from w  ww  .j  ava  2 s . c om*/
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    GL11.glColor3f(1, 1, 0);

    GL11.glPushMatrix();
    GL11.glRotatef(angle, 0, 0, 1);
    /*
    GL11.glBegin(GL11.GL_QUADS);
    for (int row = 0; row < vertices.length; row = row + 3) {
    double x = vertices[row];
    double y = vertices[row + 1];
    double z = vertices[row + 2];
    GL11.glVertex3d(x, y, z);
    }
    GL11.glEnd();
    */

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

    // Draw the vertices
    GL11.glDrawArrays(GL11.GL_QUADS, 0, vertices.length / 3);

    // Put everything back to default (deselect)
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);

    GL11.glPopMatrix();

    angle = angle + .10f;
    frameCounter++;
    long currentTime = System.nanoTime();
    long timeDifference = currentTime - lastTime;
    double fps = 1000000000.0 / timeDifference;
    System.out.printf("FPS: %.3f\n", fps);
    lastTime = currentTime;
}

From source file:br.com.perin.renderEngine.Loader.java

private int createVAO() {
    int vaoID = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoID);
    return vaoID;
}

From source file:br.com.perin.renderEngine.Loader.java

private void unbindVAO() {
    GL30.glBindVertexArray(0);
}

From source file:br.com.perin.renderEngine.Renderer.java

public void render(RawModel model) {
    GL30.glBindVertexArray(model.getVaoId());
    GL20.glEnableVertexAttribArray(0);/* ww w  .java 2  s.c om*/
    GL11.glDrawElements(GL11.GL_TRIANGLES, model.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
}

From source file:br.com.perin.renderEngine.Renderer.java

public void render(TexturedModel model) {
    RawModel raw = model.getRawModel();/*from  w  w  w .ja  v a  2 s .co m*/
    GL30.glBindVertexArray(raw.getVaoId());
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getId());
    // Essa linha est com problemas.
    GL11.glDrawElements(GL11.GL_TRIANGLES, raw.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL30.glBindVertexArray(0);
}

From source file:com.adavr.player.globjects.VertexArray.java

License:Open Source License

public static void bind(VertexArray va) {
    GL30.glBindVertexArray(va.id);
}

From source file:com.adavr.player.globjects.VertexArray.java

License:Open Source License

public static void unbind() {
    GL30.glBindVertexArray(0);
}

From source file:com.badlogic.gdx.backends.jglfw.JglfwGL30.java

License:Apache License

@Override
public void glBindVertexArray(int array) {
    GL30.glBindVertexArray(array);
}

From source file:com.flowpowered.caustic.lwjgl.gl30.GL30VertexArray.java

License:MIT License

@Override
public void setData(VertexData vertexData) {
    checkCreated();/*from w ww. j a va2s  .com*/
    // Generate a new indices buffer if we don't have one yet
    if (indicesBufferID == 0) {
        indicesBufferID = GL15.glGenBuffers();
    }
    // Bind the indices buffer
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBufferID);
    // Get the new count of indices
    final int newIndicesCount = vertexData.getIndicesCount();
    // If the new count is greater than or 50% smaller than the old one, we'll reallocate the memory
    // In the first case because we need more space, in the other to save space
    if (newIndicesCount > indicesCount || newIndicesCount <= indicesCount * 0.5) {
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, vertexData.getIndicesBuffer(), GL15.GL_STATIC_DRAW);
    } else {
        // Else, we replace the data with the new one, but we don't resize, so some old data might be left trailing in the buffer
        GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, vertexData.getIndicesBuffer());
    }
    // Unbind the indices buffer
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    // Update the total indices count
    indicesCount = newIndicesCount;
    // Ensure the count fits under the total one
    indicesDrawCount = indicesDrawCount <= 0 ? indicesCount : Math.min(indicesDrawCount, indicesCount);
    // Ensure that the indices offset and count fits inside the valid part of the buffer
    indicesOffset = Math.min(indicesOffset, indicesDrawCount - 1);
    indicesDrawCount -= indicesOffset;
    // Bind the vao
    GL30.glBindVertexArray(id);
    // Create a new array of attribute buffers ID of the correct size
    final int attributeCount = vertexData.getAttributeCount();
    final int[] newAttributeBufferIDs = new int[attributeCount];
    // Copy all the old buffer IDs that will fit in the new array so we can reuse them
    System.arraycopy(attributeBufferIDs, 0, newAttributeBufferIDs, 0,
            Math.min(attributeBufferIDs.length, newAttributeBufferIDs.length));
    // Delete any buffers that we don't need (new array is smaller than the previous one)
    for (int i = newAttributeBufferIDs.length; i < attributeBufferIDs.length; i++) {
        GL15.glDeleteBuffers(attributeBufferIDs[i]);
    }
    // Create new buffers if necessary (new array is larger than the previous one)
    for (int i = attributeBufferIDs.length; i < newAttributeBufferIDs.length; i++) {
        newAttributeBufferIDs[i] = GL15.glGenBuffers();
    }
    // Copy the old valid attribute buffer sizes
    final int[] newAttributeBufferSizes = new int[attributeCount];
    System.arraycopy(attributeBufferSizes, 0, newAttributeBufferSizes, 0,
            Math.min(attributeBufferSizes.length, newAttributeBufferSizes.length));
    // Upload the new vertex data
    for (int i = 0; i < attributeCount; i++) {
        final VertexAttribute attribute = vertexData.getAttribute(i);
        final ByteBuffer attributeData = attribute.getData();
        // Get the current buffer size
        final int bufferSize = newAttributeBufferSizes[i];
        // Get the new buffer size
        final int newBufferSize = attributeData.remaining();
        // Bind the target buffer
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, newAttributeBufferIDs[i]);
        // If the new count is greater than or 50% smaller than the old one, we'll reallocate the memory
        if (newBufferSize > bufferSize || newBufferSize <= bufferSize * 0.5) {
            GL15.glBufferData(GL15.GL_ARRAY_BUFFER, attributeData, GL15.GL_STATIC_DRAW);
        } else {
            // Else, we replace the data with the new one, but we don't resize, so some old data might be left trailing in the buffer
            GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, attributeData);
        }
        // Update the buffer size to the new one
        newAttributeBufferSizes[i] = newBufferSize;
        // Next, we add the pointer to the data in the vao
        // We have three ways to interpret integer data
        if (attribute.getType().isInteger() && attribute.getUploadMode() == UploadMode.KEEP_INT) {
            // Directly as an int
            GL30.glVertexAttribIPointer(i, attribute.getSize(), attribute.getType().getGLConstant(), 0, 0);
        } else {
            // Or as a float, normalized or not
            GL20.glVertexAttribPointer(i, attribute.getSize(), attribute.getType().getGLConstant(),
                    attribute.getUploadMode().normalize(), 0, 0);
        }
        // Finally enable the attribute
        GL20.glEnableVertexAttribArray(i);
    }
    // Unbind the last vbo
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    // Unbind the vao
    GL30.glBindVertexArray(0);
    // Update the attribute buffer IDs to the new ones
    attributeBufferIDs = newAttributeBufferIDs;
    // Update the attribute buffer sizes to the new ones
    attributeBufferSizes = newAttributeBufferSizes;
    // Check for errors
    LWJGLUtil.checkForGLError();
}