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:model.ModelMD2.java

@Override
public void destroy() {
    //Delete VAO//from  ww  w.  j ava 2 s  .c om
    GL30.glBindVertexArray(vao_id);
    {
        for (int i = 0; i < 6; i++) {
            GL20.glDisableVertexAttribArray(i);
        }

        //Delete VBOs
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
        for (int i = 0; i < frame_ids.length; i++) {
            GL15.glDeleteBuffers(frame_ids[i]);
        }
    }
    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(vao_id);
    GL11.glDeleteTextures(tex_id);
}

From source file:model.ModelMD2.java

@Override
public void draw(float frame, float[] vpMatrix, float[] matrix, RenderEngine engine) {
    if (frame < 0 || frame > header.num_frames - 1)
        return;/*  w w  w.  j  a  v a 2 s  .  c o m*/

    //Select current frame and next
    int frame_0 = frame_ids[(int) Math.floor(frame)];

    int frame_1 = frame_ids[(int) Math.min(Math.ceil(frame), header.num_frames - 1)];
    //Upload frame interpolation

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_id);

    ShaderUtils.useProgram(shader_id);
    {
        //Upload uniform values
        ShaderUtils.setUniformMatrix4(shader_id, "viewprojMatrix", vpMatrix);
        ShaderUtils.setUniformMatrix4(shader_id, "modelMatrix", matrix);
        ShaderUtils.setUniformVar(shader_id, "frame_interpolated", (float) (frame - Math.floor(frame)));
        //ShaderUtils.setUniformVar(shader_id, "cameraDir", engine.camera.yaw, engine.camera.pitch, engine.camera.roll);
        //Bind frames to VAO
        GL30.glBindVertexArray(vao_id);
        {

            GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, frame_0);//Bind frame 0
            {
                GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 32, 0);
                GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 32, 12);
                GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 32, 20);
            }
            GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

            GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, frame_1);//Bind frame 1
            {
                GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, 32, 0);
                GL20.glVertexAttribPointer(4, 2, GL11.GL_FLOAT, false, 32, 12);
                GL20.glVertexAttribPointer(5, 3, GL11.GL_FLOAT, false, 32, 20);
            }

            GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

            //Enable attribs and render
            for (int i = 0; i < 6; i++) {
                GL20.glEnableVertexAttribArray(i);
            }
            {
                GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, header.num_tris * 3);
            }
            for (int i = 0; i < 6; i++) {
                GL20.glDisableVertexAttribArray(i);
            }

        }
        GL30.glBindVertexArray(0);
    }
    ShaderUtils.useProgram(0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}

From source file:Model.Render.java

public void render(Model model) {
    GL30.glBindVertexArray(model.getVaoID());
    GL20.glEnableVertexAttribArray(0);// w w w  .j a v a  2 s .  c om
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, model.getVertexCount());
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexArrayObjectHelper.java

License:Apache License

public void bind(int vaoID) {
    GL30.glBindVertexArray(vaoID);
}

From source file:net.smert.frameworkgl.opengl.helpers.VertexArrayObjectHelper.java

License:Apache License

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

From source file:opengl.test.Demo.java

@Override
protected void dispose() {
    this.caro.dispose();
    this.gt.dispose();
    this.c.dispose();
    this.table.deleteProgram();
    this.tivi.deleteProgram();

    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(this.vao);

}

From source file:opengl.test.object.CaroTable.java

@Override
protected void initVertex() {
    GL30.glBindVertexArray(vao);//bind vao  

    // position        color       texCoord

    float[] data = new float[] { -0.5f, -0.5f, 0f, 1f, 1f, 1f, 0f, 0f, 0.5f, -0.5f, 0f, 1f, 1f, 1f, 1f, 0f,
            -0.5f, 0.5f, 0f, 1f, 1f, 1f, 0f, 1f, 0.5f, 0.5f, 0f, 1f, 1f, 1f, 1f, 1f };

    dataBuffer = BufferUtils.createFloatBuffer(data.length);
    dataBuffer.put(data);//  ww w.ja v  a2s  .  c om
    dataBuffer.flip();
    Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity  : " + dataBuffer.capacity());

    this.vbo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, dataBuffer, GL15.GL_STATIC_DRAW);

    this.VertexAttribPointer();

    int[] indices = { 0, 1, 2, 2, 1, 3 };
    IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indices.length);
    indicesBuffer.put(indices);
    indicesBuffer.flip();
    this.ebo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_DYNAMIC_DRAW);

    IntBuffer w = BufferUtils.createIntBuffer(1);
    IntBuffer h = BufferUtils.createIntBuffer(1);
    IntBuffer comp = BufferUtils.createIntBuffer(1);
    STBImage.stbi_set_flip_vertically_on_load(1);
    ByteBuffer image = STBImage.stbi_load("resource/3x3grid.png", w, h, comp, 0);

    int weight = w.get(0);
    int height = h.get(0);
    int compe = comp.get(0);

    Logger.getGlobal().log(Level.FINEST,
            "STBImage load status : " + weight + " " + height + " " + compe + " " + image);

    textureID = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

    GL30.glBindVertexArray(0);//unbind vao
}

From source file:opengl.test.object.CaroTable.java

@Override
public void render() {

    this.bind();// use porgrma --> ket thuc disable program

    GL30.glBindVertexArray(this.vao);// bind vao -- > unbind vao
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    this.VertexAttribPointer();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);

    GL20.glEnableVertexAttribArray(0);// set index ve 0 

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0);

    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}

From source file:opengl.test.object.cube.wall.java

/**
 * Must be override/*from   w  w w.ja v a2  s  . com*/
 */
@Override
protected void initVertex() {

    GL30.glBindVertexArray(vao);//bind

    IntBuffer w = BufferUtils.createIntBuffer(1);
    IntBuffer h = BufferUtils.createIntBuffer(1);
    IntBuffer comp = BufferUtils.createIntBuffer(1);
    STBImage.stbi_set_flip_vertically_on_load(1);
    ByteBuffer image = STBImage.stbi_load(this.path, w, h, comp, 0);

    int weight = w.get(0);
    int height = h.get(0);
    int compe = comp.get(0);
    //System.out.println(weight+":"+height+":"+this.path);
    float[] data = new float[] { -x, -y, 0f, 1f, 1f, 1f, 0f, 0f, x, -y, 0f, 1f, 1f, 1f,
            (2 * x) * (this.repeatCount), 0f, -x, y, 0f, 1f, 1f, 1f, 0f, (2 * y) * (this.repeatCount), x, y, 0f,
            1f, 1f, 1f, (2 * x) * (this.repeatCount), (2 * y) * (this.repeatCount), };
    dataBuffer = BufferUtils.createFloatBuffer(data.length);
    dataBuffer.put(data);
    dataBuffer.flip();
    Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity  : " + dataBuffer.capacity());

    this.vbo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, dataBuffer, GL15.GL_STATIC_DRAW);

    this.VertexAttribPointer();

    int[] indices = { 0, 1, 2, 2, 1, 3, };
    IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indices.length);
    indicesBuffer.put(indices);
    indicesBuffer.flip();
    this.ebo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_DYNAMIC_DRAW);

    textureID = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

    GL11.glTexParameteri(textureID, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(textureID, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

    GL30.glBindVertexArray(0);//unbind
}

From source file:opengl.test.object.cube.wall.java

@Override
public void render() {
    this.bind();// use porgrma --> ket thuc disable program

    GL30.glBindVertexArray(this.vao);// bind vao -- > unbind vao
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    this.VertexAttribPointer();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);

    GL20.glEnableVertexAttribArray(0);// set index ve 0 

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glDrawElements(GL11.GL_TRIANGLE_STRIP, 6, GL11.GL_UNSIGNED_INT, 0);

    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}