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.redthirddivision.quad.rendering.renderers.GuiRenderer.java

License:Apache License

@Override
public void render(ArrayList<GuiTexture> elements) {
    shader.start();/*from   w ww  . j  a  v a 2s .  co m*/

    GL30.glBindVertexArray(quad.getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    for (GuiTexture gui : elements) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, gui.getTexture());
        Matrix4f matrix = MathHelper.createTransformationMatrix(gui.getPosition(), gui.getScale(),
                new Vector2f(0, 0));
        shader.loadTransformation(matrix);
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount());
    }

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);

    shader.stop();
}

From source file:com.redthirddivision.quad.rendering.renderers.TerrainRenderer.java

License:Apache License

@Override
protected void prepare(Terrain terrain) {
    Model prim = terrain.getModel();//from ww w. ja  v  a 2s  .co m
    GL30.glBindVertexArray(prim.getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    bindTextures(terrain);
    shader.loadShine(1, 0);
}

From source file:com.redthirddivision.quad.rendering.renderers.TerrainRenderer.java

License:Apache License

@Override
protected void unbindTexturedModel() {
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
}

From source file:com.rfdickerson.openworld.CubeGeometry.java

@Override
void init() {//  ww  w  . j a va  2 s .  com

    float[] vertices = { -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f,
            0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f };

    byte[] indices = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 4, 3, 5, 0, 4, 6, 0, 6, 1

    };

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

    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
    verticesBuffer.put(vertices);
    verticesBuffer.flip();

    //vertexCount = 6;

    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, 3, GL11.GL_FLOAT, false, 0, 0);
    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.isLoaded = true;

    exitOnGLError("init terrain patch");

}

From source file:com.rfdickerson.openworld.CubeGeometry.java

@Override
void draw(SceneNode node) {

    if (!this.isLoaded) {
        this.init();
    } else {/*  www.  j  av  a  2 s .com*/

        GLSLShaderService shaderService = GLSLShaderService.getInstance();
        // use shader
        Shader basic = shaderService.findShader("basic");
        if (basic == null) {
            log.error("Could not find shader");
        } else {
            //shaderService.useShader(basic);
            //basic.setUniform4f("projectionMatrix", c.getProjectionMatrix());
            //basic.setUniform4f("viewMatrix", c.getViewMatrix());
            //basic.setUniform4f("modelMatrix", t);
            basic.setUniform4f("MVPMatrix", node.getMVPMatrix());
            basic.setUniform4f("MVMatrix", node.getMVMatrix());
            basic.setUniform3f("NormalMatrix", node.getNormalMatrix());

            shaderService.useShader(basic);

            GL20.glBindAttribLocation(basic.getProgramID(), 0, "in_Position");
        }

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

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

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

        GL20.glDisableVertexAttribArray(0);
        GL30.glBindVertexArray(0);
    }

    exitOnGLError("draw terrain patch");

}

From source file:com.rfdickerson.openworld.CubeGeometry.java

@Override
void cleanup() {/*from  w w  w  . j  av  a  2  s  .  c o m*/

    log.info("Cleaning up the SimpleTerrain");

    GL20.glDisableVertexAttribArray(0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboId);

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

    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(vaoId);

    this.isLoaded = false;

}

From source file:com.rfdickerson.openworld.RenderSurface.java

@Override
void init() {/*from ww  w  .java  2 s.c om*/

    float[] vertices = { -0.5f, 0f, -0.5f, -0.5f, 0f, 0.5f, 0.5f, 0f, 0.5f, 0.5f, 0f, -0.5f

    };

    byte[] indices = { 0, 1, 3, 1, 2, 3 };

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

    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
    verticesBuffer.put(vertices);
    verticesBuffer.flip();

    //vertexCount = 6;

    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, 3, GL11.GL_FLOAT, false, 0, 0);
    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.isLoaded = true;

    exitOnGLError("init terrain patch");

}

From source file:com.rfdickerson.openworld.RenderSurface.java

@Override
void draw(SceneNode node) {

    if (!this.isLoaded) {
        this.init();
    } else {//from   w  w w . j  ava 2 s  . co  m

        GLSLShaderService shaderService = GLSLShaderService.getInstance();
        // use shader
        Shader basic = shaderService.findShader("basic");
        if (basic == null) {
            log.error("Could not find shader");
        } else {
            //shaderService.useShader(basic);
            //basic.setUniform4f("projectionMatrix", c.getProjectionMatrix());
            //basic.setUniform4f("viewMatrix", c.getViewMatrix());
            //basic.setUniform4f("modelMatrix", t);

            shaderService.useShader(basic);

            GL20.glBindAttribLocation(basic.getProgramID(), 0, "in_Position");
        }

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

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

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

        GL20.glDisableVertexAttribArray(0);
        GL30.glBindVertexArray(0);
    }

    exitOnGLError("draw terrain patch");

}

From source file:com.samrj.devil.gl.VAO.java

private void bind() {
    GL30.glBindVertexArray(id);
}

From source file:com.samrj.devil.gl.VAO.java

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