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:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

/**
 * Render the Object./*from  w  w w .  j  a  va 2s . c o  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.grillecube.client.opengl.GLVertexArray.java

/** enable the attributes */
public void enableAttribute(int id) {
    GL20.glEnableVertexAttribArray(id);
}

From source file:com.kauridev.lunarfever.graphics.VertexArray.java

License:Open Source License

public void bind() {
    int offset = 0;
    int stride = totalNumComponents * 4;

    for (VertexAttribute attribute : attributes) {
        buffer.position(offset);//  w w w .j  a  va 2  s  . c  om
        GL20.glEnableVertexAttribArray(attribute.location);
        GL20.glVertexAttribPointer(attribute.location, attribute.numComponents, false, stride, buffer);
        offset += attribute.numComponents;
    }
}

From source file:com.opengrave.og.base.Renderable2D.java

License:Open Source License

@Override
public void renderForPicking(Matrix4f matrix, Pickable object) {
    dealWithChange();/*from   w w w.j  a  va  2s. co m*/
    if (vertexList.size() == 0) {
        return;
    }
    int pID = Resources.loadShader("pickinggui.vs", "pickinggui.fs").getProgram();
    GL20.glUseProgram(pID);
    GL30.glBindVertexArray(vaoID);
    GL20.glEnableVertexAttribArray(0);
    Util.setMatrices(pID, location2d);
    Picking.registerObject(pID, getContext(), object);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexList.size());
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
}

From source file:com.opengrave.og.base.Renderable2D.java

License:Open Source License

@Override
public void render(Matrix4f matrix, RenderStyle style) {
    Util.checkErr();/*  w w w.  j  av a  2 s .  c o  m*/
    dealWithChange();
    Util.checkErr();
    if (vertexList.size() == 0) {
        return;
    }
    int pID = Resources.loadShader("gui.vs", "gui.fs").getProgram();
    GL20.glUseProgram(pID);
    GL30.glBindVertexArray(vaoID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    Util.checkErr();
    if (texture != null) {
        texture.bind(GL13.GL_TEXTURE0);
    }
    Util.setMatrices(pID, location2d);
    Util.checkErr();

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexList.size());
    Util.checkErr();
    if (texture != null) {
        texture.unbind();
    }
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    Util.checkErr();

    GL30.glBindVertexArray(0);
    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    Util.checkErr();
}

From source file:com.opengrave.og.base.Renderable3D.java

License:Open Source License

@Override
public void render(Matrix4f matrix, RenderStyle style) {
    dealWithChange();/*  ww w  .  j av  a 2  s .  co  m*/
    int pID = Resources.loadShader("model.vs", "model.fs").getProgram();
    GL20.glUseProgram(pID);
    int texture = GL20.glGetUniformLocation(pID, "texture");
    int shadow = GL20.glGetUniformLocation(pID, "shadowMap");
    GL20.glUniform1i(texture, 0);
    GL20.glUniform1i(shadow, 1);
    GL30.glBindVertexArray(vao_ID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    GL20.glBindAttribLocation(pID, 0, "in_Position");
    GL20.glBindAttribLocation(pID, 1, "in_Normal");
    GL20.glBindAttribLocation(pID, 2, "in_TextureCoord");

    Util.checkErr();
    if (matList != null && matList.valid()) {
        matList.bind(pID, GL13.GL_TEXTURE0);
        Util.loadMaterials(matList, pID);

    }
    Util.checkErr();
    getContext().setMatrices(pID, matrix);
    getContext().bindShadowData(GL13.GL_TEXTURE2);
    getContext().bindLights(pID, GL13.GL_TEXTURE3);
    Util.setRenderStyle(pID, style);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID);
    GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    getContext().unbindLights();
    getContext().unbindShadowData();

    if (matList != null && matList.valid()) {
        matList.unbind();
    }
    Util.checkErr();

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    Util.checkErr();

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

From source file:com.opengrave.og.base.Renderable3D.java

License:Open Source License

@Override
public void renderShadows(Matrix4f matrix, Shadow shadow) {
    dealWithChange();/*from ww w  .j  av  a 2  s.c  om*/

    int pID = Resources.loadShader("model.vs", "castshadow.fs").getProgram();
    GL20.glUseProgram(pID);
    GL30.glBindVertexArray(vao_ID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glBindAttribLocation(pID, 0, "in_Position");

    Util.checkErr();
    getContext().setShadowMatrices(pID, matrix, shadow);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID);
    GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    Util.checkErr();

    GL20.glDisableVertexAttribArray(0);
    Util.checkErr();

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

From source file:com.opengrave.og.base.Renderable3D.java

License:Open Source License

@Override
public void renderForPicking(Matrix4f matrix, Pickable object) {
    dealWithChange();/*from w ww . ja va2s  .  com*/
    int pID = Resources.loadShader("model.vs", "pickingmodel.fs").getProgram();
    GL20.glUseProgram(pID);
    GL30.glBindVertexArray(vao_ID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glBindAttribLocation(pID, 0, "in_Position");

    Util.checkErr();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID);
    getContext().setMatrices(pID, matrix);
    Picking.registerObject(pID, getContext(), object);
    GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    Util.checkErr();

    GL20.glDisableVertexAttribArray(0);
    Util.checkErr();

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

From source file:com.opengrave.og.base.RenderableBoneAnimated.java

License:Open Source License

@Override
public void render(Matrix4f matrix, RenderStyle style) {
    // if (!visible) {
    // return;//from   w  w w . j  a  va2 s . c om
    // }
    GL11.glDisable(GL11.GL_CULL_FACE); // TODO Enable Face Culling, and be
    // absolutely sure that all tris are
    // facing the correct way
    dealWithChange();

    int pID = Resources.loadShader("animmodel.vs", "animmodel.fs").getProgram();
    GL20.glUseProgram(pID);
    int texture = GL20.glGetUniformLocation(pID, "texture");
    int shadow = GL20.glGetUniformLocation(pID, "shadowMap");
    GL20.glUniform1i(texture, 0);
    GL20.glUniform1i(shadow, 1);
    GL30.glBindVertexArray(vao_ID);
    GL20.glBindAttribLocation(pID, 0, "in_Position");
    GL20.glBindAttribLocation(pID, 1, "in_Normal");
    GL20.glBindAttribLocation(pID, 2, "in_TextureCoord");
    GL20.glBindAttribLocation(pID, 3, "in_BoneID");
    GL20.glBindAttribLocation(pID, 4, "in_BoneWeight");

    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    GL20.glEnableVertexAttribArray(3);
    GL20.glEnableVertexAttribArray(4);
    if (matList != null && matList.valid()) {
        matList.bind(pID, GL13.GL_TEXTURE0);
        Util.loadMaterials(matList, pID);

    }
    setBonesUniform(pID);

    getContext().setMatrices(pID, matrix);
    getContext().bindShadowData(GL13.GL_TEXTURE2);
    getContext().bindLights(pID, GL13.GL_TEXTURE3);
    Util.setRenderStyle(pID, style);
    // GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertCount);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID);
    GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    getContext().unbindLights();
    getContext().unbindShadowData();
    if (matList != null && matList.valid()) {
        matList.unbind();
    }
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL20.glDisableVertexAttribArray(3);
    GL20.glDisableVertexAttribArray(4);

    GL20.glUseProgram(0);
    GL30.glBindVertexArray(0);

    GL11.glEnable(GL11.GL_CULL_FACE);
}

From source file:com.opengrave.og.base.RenderableBoneAnimated.java

License:Open Source License

@Override
public void renderShadows(Matrix4f matrix, Shadow shadow) {
    // if (!visible) {
    // return;/*w w  w . j a  v a 2s. co m*/
    // }
    dealWithChange();

    int pID = Resources.loadShader("animmodel.vs", "animmodel.fs").getProgram();
    GL20.glUseProgram(pID);
    GL30.glBindVertexArray(vao_ID);
    GL20.glBindAttribLocation(pID, 0, "in_Position");
    GL20.glBindAttribLocation(pID, 3, "in_BoneID");
    GL20.glBindAttribLocation(pID, 4, "in_BoneWeight");

    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(3);
    GL20.glEnableVertexAttribArray(4);
    setBonesUniform(pID);
    getContext().setShadowMatrices(pID, matrix, shadow);
    // GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertCount);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID);
    GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(3);
    GL20.glDisableVertexAttribArray(4);

    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);

}