Example usage for org.lwjgl.opengl GL11 glDrawElements

List of usage examples for org.lwjgl.opengl GL11 glDrawElements

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glDrawElements.

Prototype

public static void glDrawElements(@NativeType("GLenum") int mode, @NativeType("GLsizei") int count,
        @NativeType("GLenum") int type, @NativeType("void const *") long indices) 

Source Link

Document

Constructs a sequence of geometric primitives by successively transferring elements for count vertices to the GL.

Usage

From source file:com.owens.oobjloader.lwjgl.VBO.java

License:BSD License

public void render() {

    GL11.glEnable(GL11.GL_TEXTURE_2D);//from   w  ww.j av a 2 s  .c o m
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textId); // Bind The Texture

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, verticeAttributesID);

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, ATTR_V_STRIDE2_BYTES, ATTR_V_OFFSET_BYTES);

    GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
    GL11.glNormalPointer(GL11.GL_FLOAT, ATTR_N_STRIDE2_BYTES, ATTR_N_OFFSET_BYTES);

    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, ATTR_T_STRIDE2_BYTES, ATTR_T_OFFSET_BYTES);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesID);
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_INT, 0);

    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
}

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

License:Apache License

public void render(Map<Model, ArrayList<Entity>> entities) {
    for (Model model : entities.keySet()) {
        prepare(model);//w  w  w  .  ja v a 2 s  .  co  m
        ArrayList<Entity> batch = entities.get(model);
        for (Entity e : batch) {
            prepareInstance(e);
            GL11.glDrawElements(GL11.GL_TRIANGLES, model.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
        }

        unbindTexturedModel();
    }
}

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

License:Apache License

@Override
public void render(ArrayList<Terrain> terrains) {
    for (Terrain terrain : terrains) {
        prepare(terrain);// w ww. j  ava  2 s.  c om
        prepareInstance(terrain);
        GL11.glDrawElements(GL11.GL_TRIANGLES, terrain.getModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
        unbindTexturedModel();
    }
}

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

@Override
void draw(SceneNode node) {

    if (!this.isLoaded) {
        this.init();
    } else {//from  w w w.java  2  s  . c o 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);
            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.RenderSurface.java

@Override
void draw(SceneNode node) {

    if (!this.isLoaded) {
        this.init();
    } else {/* ww w .ja va  2s  . c o  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.DGL.java

License:Open Source License

/**
 * Draws the given vertex data using the given primitive mode. A shader must
 * be bound.//from   w w w .  j  a v a2 s.c om
 * 
 * @param <T> A type of vertex data.
 * @param data The vertex data to render.
 * @param mode An OpenGL primitive draw mode.
 * @return The given vertex data.
 */
public static <T extends VertexData> T draw(T data, int mode) {
    if (boundProgram == null)
        throw new IllegalStateException("No shader program is in use.");

    int verts = data.numVertices();
    int inds = data.numIndices();

    VAO.bindFor(data, boundProgram, () -> {
        if (inds < 0)
            GL11.glDrawArrays(mode, 0, verts);
        else
            GL11.glDrawElements(mode, inds, GL11.GL_UNSIGNED_INT, 0);
    });

    return data;
}

From source file:com.voxelplugineering.voxelsniper.render.buffer.BufferSection.java

License:Open Source License

public void draw() {

    // Bind to the index VBO that has all the information about the order of
    // the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);

    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}

From source file:com.xrbpowered.gl.res.shaders.FeedbackVertices.java

License:Open Source License

public void draw() {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboFeedbackId);
    renderShader.use();/*from   w ww .ja v  a 2  s . c o m*/
    renderShader.info.enableAttribs();
    renderShader.info.initAttribPointers();

    if (vboiId != GL11.GL_INVALID_VALUE) {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL11.glDrawElements(GL11.GL_POINTS, countElements, GL11.GL_UNSIGNED_INT, 0);
    } else {
        GL11.glDrawArrays(GL11.GL_POINTS, 0, countElements);
    }

    renderShader.info.disableAttribs();
    renderShader.unuse();
    GL30.glBindVertexArray(0);
}

From source file:com.xrbpowered.gl.res.StaticMesh.java

License:Open Source License

public void drawCall() {
    if (vboiId != GL11.GL_INVALID_VALUE) {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL11.glDrawElements(drawMode, countElements, GL11.GL_UNSIGNED_SHORT, 0);
    } else {//ww w  . jav  a2 s  .  c om
        GL11.glDrawArrays(drawMode, 0, countElements);
    }
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void drawIndexedQuads(float coords[], byte colors[], int numVertices) {

    int numQuads = numVertices / 4;
    int numIndices = numQuads * 2 * 3;

    // for some reason (compatibility maybe?) JavaFX keeps all its data on the JVM heap (eg, in arrays)
    // sadly, LWJGL won't let use attribute offsets on heap buffers, so we need to copy into direct buffers
    // hopefully we're not drawing that many quads, and this won't be too slow

    // pos,tex coords
    indexedQuadsCoordsBuf = updateBuffer(indexedQuadsCoordsBuf, coords, numVertices * PosTexBytes);
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, PosTexBytes,
            MemoryUtil.memAddress(indexedQuadsCoordsBuf) + PosOffsetBytes);
    // index 1 is color, handled below
    GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, PosTexBytes,
            MemoryUtil.memAddress(indexedQuadsCoordsBuf) + Tex0OffsetBytes);
    GL20.glVertexAttribPointer(3, 2, GL11.GL_FLOAT, false, PosTexBytes,
            MemoryUtil.memAddress(indexedQuadsCoordsBuf) + Tex1OffsetBytes);

    // colors/*from  ww w . j  a  va2  s .c  om*/
    indexedQuadsColorsBuf = updateBuffer(indexedQuadsColorsBuf, colors, numVertices * ColorBytes);
    GL20.glVertexAttribPointer(1, 4, GL11.GL_UNSIGNED_BYTE, true, ColorBytes, indexedQuadsColorsBuf);

    GL11.glDrawElements(GL11.GL_TRIANGLES, numIndices, GL11.GL_UNSIGNED_SHORT, 0);
}