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.opengrave.og.base.RenderableParticles.java

License:Open Source License

@Override
public void render(Matrix4f matrix, RenderStyle style) {
    dealWithChange();//  w w  w  .j  av a 2s .c o  m
    if (matList == null || !matList.valid()) {
        return;
    }
    GL30.glBindVertexArray(idVao);
    int pID = Resources.loadShader("particle.vs", "particle.fs").getProgram();
    GL20.glUseProgram(pID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    GL20.glBindAttribLocation(pID, 0, "in_Position");
    GL20.glBindAttribLocation(pID, 1, "in_Colour");
    GL20.glBindAttribLocation(pID, 2, "in_Scale");
    Util.checkErr();
    int texture = GL20.glGetUniformLocation(pID, "tex");
    GL20.glUniform1i(texture, 0);
    int wSS = GL20.glGetUniformLocation(pID, "windowSizeScale");

    GL20.glUniform1f(wSS, getContext().width / 1024f);
    getContext().setMatrices(pID, matrix);
    if (matList != null && matList.valid()) {
        matList.bind(pID, GL13.GL_TEXTURE0);
    }
    GL11.glEnable(GL20.GL_POINT_SPRITE);
    GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    GL11.glDepthMask(false);
    GL11.glDrawArrays(GL11.GL_POINTS, 0, size);
    GL11.glDepthMask(true);
    GL11.glDisable(GL20.GL_POINT_SPRITE);
    GL11.glDisable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);

    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);
    Util.checkErr();
}

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

License:Open Source License

@Override
public void renderForPicking(Matrix4f matrix, Pickable object) {
    dealWithChange();/*ww w. j  a  v a2 s .c o m*/
    GL30.glBindVertexArray(idVao);
    int pID = Resources.loadShader("particle.vs", "pickingmodel.fs").getProgram();
    GL20.glUseProgram(pID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(2);
    GL20.glBindAttribLocation(pID, 0, "in_Position");
    GL20.glBindAttribLocation(pID, 2, "in_Scale");
    Util.checkErr();

    int wSS = GL20.glGetUniformLocation(pID, "windowSizeScale");

    GL20.glUniform1f(wSS, MainThread.lastW / 1024f);
    getContext().setMatrices(pID, matrix);
    GL11.glEnable(GL20.GL_POINT_SPRITE);
    GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    Picking.registerObject(pID, getContext(), object);
    GL11.glDrawArrays(GL11.GL_POINTS, 0, size);
    GL11.glDisable(GL20.GL_POINT_SPRITE);
    GL11.glDisable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);

    Util.checkErr();

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(2);

    Util.checkErr();

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

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

License:Open Source License

@Override
public void dealWithChange() {
    // Safely assume every frame is a new frame in terms of particle
    // positions.
    if (idVao == 0) {
        idVao = GL30.glGenVertexArrays();
    }/*from w  ww  .  j a va  2s  .c  o m*/
    GL30.glBindVertexArray(idVao);
    if (idVboColours == 0) {
        idVboColours = GL15.glGenBuffers();
    }
    if (idVboPositions == 0) {
        idVboPositions = GL15.glGenBuffers();
    }
    if (idVboScale == 0) {
        idVboScale = GL15.glGenBuffers();
    }

    size = particleList.size() * 4;
    if (positions == null || positions.capacity() != size) {
        positions = BufferUtils.createFloatBuffer(size);
    }
    if (colours == null || colours.capacity() != size) {
        colours = BufferUtils.createFloatBuffer(size);
    }
    if (scales == null || scales.capacity() != size) {
        scales = BufferUtils.createFloatBuffer(size);
    }
    positions.rewind();
    colours.rewind();
    scales.rewind();
    for (ParticlePart particle : particleList) {
        Vector3f pos = particle.getPosition().toVector3(), sca = particle.getScaleData();
        Vector4f col = particle.getColour();

        positions.put(pos.x).put(pos.y).put(pos.z).put(1f);
        colours.put(col.x).put(col.y).put(col.z).put(col.w);
        scales.put(sca.x).put(sca.y).put(sca.z).put(1f);

    }
    positions.flip();
    colours.flip();
    scales.flip();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, idVboPositions);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, positions, GL15.GL_STREAM_DRAW);
    GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, 0, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, idVboColours);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colours, GL15.GL_STREAM_DRAW);
    GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, 0, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, idVboScale);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, scales, GL15.GL_STREAM_DRAW);
    GL20.glVertexAttribPointer(2, 4, GL11.GL_FLOAT, false, 0, 0);

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

}

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

License:Open Source License

@Override
public void render(Matrix4f matrix, RenderStyle style) {
    Util.checkErr();//from w w  w. ja  v a  2  s  .  c  o  m

    dealWithChange();
    if (!visible) {
        return;
    }
    if (vertCount == 0) {
        return;
    }
    Util.checkErr();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    Util.checkErr();
    GL11.glPointSize(3f);
    Util.checkErr();
    int pID = Resources.loadShader("particle.vs", "particle.fs").getProgram();
    Util.checkErr();
    GL20.glUseProgram(pID);
    Util.checkErr();
    if (pID == 0) {
        return;
    }
    Util.checkErr();
    GL30.glBindVertexArray(vaoID);
    Util.checkErr();
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    Util.checkErr();
    int wSS = GL20.glGetUniformLocation(pID, "windowSizeScale");

    GL20.glUniform1f(wSS, MainThread.lastW / 1024f);

    getContext().setMatrices(pID, matrix);
    Util.checkErr();

    if (tex != null) {
        tex.bind(GL13.GL_TEXTURE0);
    }
    GL11.glEnable(GL20.GL_POINT_SPRITE);
    GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    GL11.glDrawArrays(GL11.GL_POINTS, 0, vertCount);

    GL11.glDisable(GL20.GL_POINT_SPRITE);
    GL11.glDisable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    if (tex != null) {
        tex.unbind();
    }
    Util.checkErr();

    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();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
}

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

License:Open Source License

@Override
public void dealWithChange() {
    if (vaoID == 0) {
        vaoID = GL30.glGenVertexArrays();
    }//from   ww w.  j  av a2  s . c  o m
    GL30.glBindVertexArray(vaoID);
    if (vboID == 0) {
        vboID = GL15.glGenBuffers();
    }
    if (vboCID == 0) {
        vboCID = GL15.glGenBuffers();
    }
    if (vbosID == 0) {
        vbosID = GL15.glGenBuffers();
    }

    if (changed) {
        changed = false;
        // vertexList.clear();
        recreate();
        synchronized (vertexList) {
            vertCount = vertexList.size();
            if (vertCount == 0) {
                return;
            }
            if (posBuffer == null || posBuffer.capacity() != vertCount * 3) {
                posBuffer = BufferUtils.createFloatBuffer(vertCount * 3);
            }
            if (colBuffer == null || colBuffer.capacity() != vertCount * 4) {
                colBuffer = BufferUtils.createFloatBuffer(vertCount * 4);
            }
            if (scaleBuffer == null || scaleBuffer.capacity() != vertCount * 4) {
                scaleBuffer = BufferUtils.createFloatBuffer(vertCount * 4);
            }
            posBuffer.position(0);
            colBuffer.position(0);
            scaleBuffer.position(0);
            for (VertexPoint va : vertexList) {
                posBuffer.put(va.x).put(va.y).put(va.z);
                colBuffer.put(va.r).put(va.g).put(va.b).put(va.a);
                scaleBuffer.put(va.size).put(va.texture).put(0f).put(0f);
            }
        }
        posBuffer.flip();
        colBuffer.flip();
        scaleBuffer.flip();

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, posBuffer, GL15.GL_STATIC_DRAW);
        GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboCID);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colBuffer, GL15.GL_STATIC_DRAW);
        GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, 0, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbosID);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, scaleBuffer, GL15.GL_STATIC_DRAW);
        GL20.glVertexAttribPointer(2, 4, GL11.GL_FLOAT, false, 0, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    }
    GL30.glBindVertexArray(0);
}

From source file:com.opengrave.og.light.Depth2DFramebuffer.java

License:Open Source License

public Depth2DFramebuffer(int size) {
    framebufferSize = size;/*from   w  w  w . java 2 s. co  m*/
    framebuffer = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
    shadowMap = new Texture2DShadowMap(framebufferSize);

    shadowMap.bindToFrameBuffer();

    // GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0);
    GL11.glDrawBuffer(GL11.GL_NONE);
    Util.checkErr();
    GL11.glReadBuffer(GL11.GL_NONE);
    int i = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);
    if (i != GL30.GL_FRAMEBUFFER_COMPLETE) {
        throw new RuntimeException("Framebuffer creation failed with code: " + i);
    }
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

    // TESTING STUFF
    count = 2;
    FloatBuffer pos = BufferUtils.createFloatBuffer(3 * 3 * count);
    FloatBuffer tex = BufferUtils.createFloatBuffer(2 * 3 * count);
    pos.put(0.75f).put(0.75f).put(0f);
    pos.put(0.75f).put(0.25f).put(0f);
    pos.put(0.25f).put(0.75f).put(0f);
    pos.put(0.25f).put(0.25f).put(0f);

    pos.put(0.75f).put(0.25f).put(0f);
    pos.put(0.25f).put(0.75f).put(0f);
    pos.flip();
    tex.put(1f).put(1f);
    tex.put(1f).put(0f);
    tex.put(0f).put(1f);
    tex.put(0f).put(0f);
    tex.put(1f).put(0f);

    tex.put(0f).put(1f);
    tex.flip();
    vao_ID = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vao_ID);
    int vbo_pos_ID = GL15.glGenBuffers();
    int vbo_tex_ID = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_pos_ID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, pos, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_tex_ID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tex, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 0, 0);
}

From source file:com.opengrave.og.light.Depth2DFramebuffer.java

License:Open Source License

public void dumpTestingImage() {
    // TESTING/*from ww w.j av  a 2 s .  c o m*/
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    int pID = Resources.loadShader("test.vs", "test.fs").getProgram();
    GL20.glUseProgram(pID);
    int shadow = GL20.glGetUniformLocation(pID, "shadowMap");
    GL20.glUniform1i(shadow, 0);
    GL30.glBindVertexArray(vao_ID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    shadowMap.bind(GL13.GL_TEXTURE0);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, count * 3);
    shadowMap.unbind();
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);

    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    // END TESTING
}

From source file:com.redthirddivision.quad.rendering.models.Model.java

License:Apache License

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

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

License:Apache License

protected void prepare(Model model) {
    GL30.glBindVertexArray(model.getVaoID());
    GL20.glEnableVertexAttribArray(0);//from   w  ww .  j a  v a  2 s. c  o m
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    Material material = model.getMaterial();
    shader.loadNumRows(material.getNumRows());
    if (material.hasTransparency())
        Util.disableCulling();
    shader.loadFakeLighting(material.isUseingFakeLighting());
    shader.loadShine(material.getShineDamper(), material.getReflectivity());

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getMaterial().getTextureID());
}

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

License:Apache License

@Override
protected void unbindTexturedModel() {
    Util.enableCulling();//from ww w.  j  av a  2 s.  c  om
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
}