Example usage for org.lwjgl.opengl GL20 glEnableVertexAttribArray

List of usage examples for org.lwjgl.opengl GL20 glEnableVertexAttribArray

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 glEnableVertexAttribArray.

Prototype

public static void glEnableVertexAttribArray(@NativeType("GLuint") int index) 

Source Link

Document

Enables a generic vertex attribute array.

Usage

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

private synchronized void render() {
    GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL20.glUseProgram(shader.getPID());// ww w .j  av a 2s.c o m
    //

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL30.glBindVertexArray(vaoId);

    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid));
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
    long offset = 0;
    int shift = 0;
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    for (Drawable object : objects) {
        Matrix4f finalMVP = new Matrix4f(mvpMat);
        Matrix4f modelMat = new Matrix4f();
        Matrix4f scaler = new Matrix4f();
        scaler.scale(object.scale * allScale);
        modelMat.translate(object.translation);
        modelMat.rotateXYZ(object.rotation.x, object.rotation.y, object.rotation.z);
        finalMVP.mul(modelMat);
        finalMVP.mul(scaler);
        finalMVP.get(0, matBuff);
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid_charmap));
        }
        GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff);
        GL20.glUniform1i(shader.getInverseLocation(), object.inverseAlpha ? 1 : 0);
        if (object.isVisible())
            GL32.glDrawElementsBaseVertex(GL11.GL_TRIANGLES, object.getIndices().length, GL11.GL_UNSIGNED_BYTE,
                    offset, shift);

        offset += object.getIndices().length;
        shift += object.getVertex().length;
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid));
        }
    }
    render2d(offset, shift);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
    //
    GL20.glUseProgram(0);
    glfwSwapBuffers(window);
    glfwPollEvents();

}

From source file:me.thehutch.fusion.engine.render.opengl.gl30.OpenGL30VertexArray.java

License:Open Source License

@Override
public void addAttribute(int index, int size, TFloatList data) {
    ensureCreated("VertexArray must be created to add an attribute.");

    if (index > GL11.glGetInteger(GL_MAX_VERTEX_ATTRIBS)) {
        throw new IllegalArgumentException("Vertex attribute index exceeds maximum vertex attribute index.");
    }// w w  w.j a v  a  2 s . com
    // Put the indices into an FloatBuffer
    final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size());
    data.forEach((float f) -> {
        buffer.put(f);
        return true;
    });
    buffer.flip();

    // Bind the VAO
    GL30.glBindVertexArray(vao);
    // Generate and bind the attribute buffer
    final int id = GL15.glGenBuffers();
    GL15.glBindBuffer(GL_ARRAY_BUFFER, id);
    // Set the attribute data
    GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
    // Enable the vertex attribute
    GL20.glEnableVertexAttribArray(index);
    // Set the vertex attribute settings
    GL20.glVertexAttribPointer(index, size, DataType.FLOAT.getGLConstant(), false, 0, 0L);
    // Disable the vertex attribute
    GL20.glDisableVertexAttribArray(index);
    // Unbind the attribute buffer
    GL15.glBindBuffer(GL_ARRAY_BUFFER, 0);
    // Unbind the VAO
    GL30.glBindVertexArray(vao);

    // Add the buffer id to the attributes list
    this.attributes.insert(index, id);

    // Check for errors
    RenderUtil.checkGLError();
}

From source file:me.thehutch.fusion.engine.render.opengl.gl30.OpenGL30VertexArray.java

License:Open Source License

@Override
public void draw() {
    ensureCreated("VertexArray must be created to draw.");

    //Bind the vertex array object
    GL30.glBindVertexArray(vao);/*from  w w  w .  j av  a 2s. c om*/

    // Enable the vertex attributes
    for (int i = 0; i < attributes.size(); ++i) {
        GL20.glEnableVertexAttribArray(i);
    }

    // Bind the index buffer
    GL15.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
    // Draw the vertex elements
    GL11.glDrawElements(GL_TRIANGLES, drawCount, DataType.UNSIGNED_INT.getGLConstant(), 0L);
    // Unbind the index buffer
    GL15.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    // Disable the vertex attributes
    for (int i = 0; i < attributes.size(); ++i) {
        GL20.glDisableVertexAttribArray(i);
    }

    // Unbind the vertex array object
    GL30.glBindVertexArray(0);
}

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

    //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);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, model.getVertexCount());
    GL20.glDisableVertexAttribArray(0);//from   w w w .  ja v  a  2  s  . c  o  m
    GL30.glBindVertexArray(0);
}

From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java

License:Apache License

/** Enables the vertex attribute with the given name
 * /*  www.  j  av a 2 s . c  o m*/
 * @param name the vertex attribute name */
public void enableVertexAttribute(String name) {
    checkContext();
    int location = fetchAttributeLocation(name);
    if (location == -1)
        return;
    GL20.glEnableVertexAttribArray(location);
}

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

License:Apache License

public void enableVertexAttribArray(int index) {
    GL20.glEnableVertexAttribArray(index);
}

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

/**
 * Method nay duoc tach rieng ra tu initVertex 
 * Vi render nhieu doi tuong neu dung Multi vbo --> truoc khi draw phai bind lai vbo --> moi lan bind lai se phai set lai VertexAttribPointer
 *//*from   w  ww  .j  a v a 2s  .c  o m*/
@Override
protected void VertexAttribPointer() {
    if (this.vbo == 0)
        throw new RuntimeException("Chua khoi tao VBO");

    int positionID = GL20.glGetAttribLocation(programID, "position");
    GL20.glEnableVertexAttribArray(positionID);
    GL20.glVertexAttribPointer(positionID, 3, GL11.GL_FLOAT, false, 8 * 4, 0);// float size = 4 byte --> next is 3*4 byte
    // size = 3 --> position = x,y,z vec3

    int colorID = GL20.glGetAttribLocation(programID, "color");
    GL20.glEnableVertexAttribArray(colorID);
    GL20.glVertexAttribPointer(colorID, 3, GL11.GL_FLOAT, false, 8 * 4, 3 * 4);
    // size = 3 --> vec3

    int texcoordID = GL20.glGetAttribLocation(programID, "texcoord");
    GL20.glEnableVertexAttribArray(texcoordID);
    GL20.glVertexAttribPointer(texcoordID, 2, GL11.GL_FLOAT, false, 8 * 4, 6 * 4);
    // size = 2 --> vec2
}

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

@Override
protected void VertexAttribPointer() {
    if (this.vbo == 0)
        throw new RuntimeException("Chua khoi tao VBO");

    int positionID = GL20.glGetAttribLocation(programID, "position");
    GL20.glEnableVertexAttribArray(positionID);
    GL20.glVertexAttribPointer(positionID, 3, GL11.GL_FLOAT, false, 8 * 4, 0);// float size = 4 byte --> next is 3*4 byte
    // size = 3 --> position = x,y,z vec3

    int colorID = GL20.glGetAttribLocation(programID, "color");
    GL20.glEnableVertexAttribArray(colorID);
    GL20.glVertexAttribPointer(colorID, 3, GL11.GL_FLOAT, false, 8 * 4, 3 * 4);
    // size = 3 --> vec3

    int texcoordID = GL20.glGetAttribLocation(programID, "texcoord");
    GL20.glEnableVertexAttribArray(texcoordID);
    GL20.glVertexAttribPointer(texcoordID, 2, GL11.GL_FLOAT, false, 8 * 4, 6 * 4);
    // size = 2 --> vec2
}