Example usage for org.lwjgl.opengl GL11 glDrawArrays

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

Introduction

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

Prototype

public static void glDrawArrays(@NativeType("GLenum") int mode, @NativeType("GLint") int first,
        @NativeType("GLsizei") int count) 

Source Link

Document

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

Usage

From source file:org.jogamp.glg2d.impl.shader.AnyModePipeline.java

License:Apache License

public void draw(int mode, FloatBuffer vertexBuffer) {
    bindBufferData(vertexBuffer);/*from  w  ww  .  j  a v  a2 s .  c om*/

    int numPts = (vertexBuffer.limit() - vertexBuffer.position()) / 2;
    GL11.glDrawArrays(mode, 0, numPts);

    unbindBuffer();
}

From source file:org.jogamp.glg2d.impl.shader.GeometryShaderStrokePipeline.java

License:Apache License

public void draw(FloatBuffer vertexBuffer, boolean close) {
    int pos = vertexBuffer.position();
    int lim = vertexBuffer.limit();
    int numPts = (lim - pos) / 2;

    if (numPts * 2 + 6 > vBuffer.capacity()) {
        vBuffer = BufferUtils.createFloatBuffer(numPts * 2 + 4);
    }//from   w  w w.  j  a  v a2s.  co m

    vBuffer.clear();

    if (close) {
        vBuffer.put(vertexBuffer.get(lim - 2));
        vBuffer.put(vertexBuffer.get(lim - 1));
        vBuffer.put(vertexBuffer);
        vBuffer.put(vertexBuffer.get(pos));
        vBuffer.put(vertexBuffer.get(pos + 1));
        vBuffer.put(vertexBuffer.get(pos + 2));
        vBuffer.put(vertexBuffer.get(pos + 3));
    } else {
        vBuffer.put(0);
        vBuffer.put(0);
        vBuffer.put(vertexBuffer);
        vBuffer.put(0);
        vBuffer.put(0);
    }

    vBuffer.flip();

    bindBuffer(vBuffer);

    if (close) {
        setDrawEnd(DRAW_END_NONE);
        GL11.glDrawArrays(GL11.GL_LINES, 0, numPts + 1);
        GL11.glDrawArrays(GL11.GL_LINES, 1, numPts);
    } else if (numPts == 2) {
        setDrawEnd(DRAW_END_BOTH);
        GL11.glDrawArrays(GL11.GL_LINES, 0, 2);
    } else {
        setDrawEnd(DRAW_END_NONE);
        GL11.glDrawArrays(GL11.GL_LINES, 1, numPts - 2);
        GL11.glDrawArrays(GL11.GL_LINES, 2, numPts - 3);

        setDrawEnd(DRAW_END_FIRST);
        GL11.glDrawArrays(GL11.GL_LINES, 0, 2);

        setDrawEnd(DRAW_END_LAST);
        GL11.glDrawArrays(GL11.GL_LINES, numPts - 2, 2);
    }

    GL20.glDisableVertexAttribArray(vertCoordLocation);
    GL20.glDisableVertexAttribArray(vertBeforeLocation);
    GL20.glDisableVertexAttribArray(vertAfterLocation);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:org.jogamp.glg2d.impl.shader.GL2ES2ImagePipeline.java

License:Apache License

public void draw(FloatBuffer interleavedVertTexBuffer) {
    bufferData(interleavedVertTexBuffer);

    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);

    GL20.glDisableVertexAttribArray(vertCoordLocation);
    GL20.glDisableVertexAttribArray(texCoordLocation);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:org.jogamp.glg2d.VertexBuffer.java

License:Apache License

/**
 * Draws the vertices and rewinds the buffer to be ready to draw next time.
 * /*from w w  w. ja va  2  s  .  c  o  m*/
 * @param gl
 *          The graphics context to use to draw
 * @param mode
 *          The mode, e.g. {@code GL#GL_LINE_STRIP}
 */
public void drawBuffer(int mode) {
    if (buffer.position() == 0) {
        return;
    }

    int count = buffer.position();
    buffer.rewind();

    GL11.glVertexPointer(2, 0, buffer);

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glDrawArrays(mode, 0, count / 2);
    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

    buffer.position(count);
}

From source file:org.meanworks.engine.render.geometry.mesh.renderers.VAOMeshRenderer.java

License:Open Source License

/**
 * Renders the mesh/*from   ww  w  .  j a  v a 2s .  c  o m*/
 */
public void render(Material material) {
    if (vertexBufferArray != null) {

        /*
         * Update matrices
         */
        material.setProperty("mProjectionView", RenderState.getProjectionViewMatrix());
        material.setProperty("mModelMatrix", RenderState.getTransformMatrix());

        /*
         * Upload material data to the graphics card
         */
        material.apply();

        vertexBufferArray.bind();
        {
            if (indexBuffer != null) {
                if (EngineConfig.usingModernOpenGL) {
                    GL11.glDrawElements(GL11.GL_TRIANGLES, numIndices, GL11.GL_UNSIGNED_INT, 0);
                } else {
                    EngineLogger.error(
                            "Tried to render using a VertexBufferRenderer while the graphics card does not support it.");
                }
            } else {
                GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.numVertices);
            }
            RenderState.addRenderedVertices(this.numVertices);
        }
        vertexBufferArray.unbind();
    } else {
        EngineLogger.error("Could not render model... VAO = null");
    }
}

From source file:org.spout.engine.renderer.GL11BatchVertexRenderer.java

License:Open Source License

@Override
protected void doFlush() {
    GL11.glNewList(displayList, GL11.GL_COMPILE);
    FloatBuffer vBuffer = BufferUtils.createFloatBuffer(vertexBuffer.size());

    vBuffer.clear();// w  w  w  . j  a v  a 2 s.c  o m
    vBuffer.put(vertexBuffer.toArray());
    vBuffer.flip();

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glVertexPointer(4, 0, vBuffer);

    /*if (useColors) {
       vBuffer.clear();
       vBuffer.put(colorBuffer.toArray());
       vBuffer.flip();
               
       GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
       GL11.glColorPointer(4, 0, vBuffer);
    }*/

    if (useNormals) {
        vBuffer.clear();
        vBuffer.put(normalBuffer.toArray());
        vBuffer.flip();

        GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
        GL11.glNormalPointer(0, vBuffer);
    }

    if (useTextures) {
        FloatBuffer temp = BufferUtils.createFloatBuffer(uvBuffer.size());
        temp.put(uvBuffer.toArray());
        temp.flip();

        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        GL11.glTexCoordPointer(2, 0, temp);
    }

    GL11.glDrawArrays(renderMode, 0, numVertices);

    GL11.glEndList();
}

From source file:org.spout.engine.renderer.GL20BatchVertexRenderer.java

License:Open Source License

/**
 * Draws this batch//  ww w  .  j  ava  2  s .com
 */
@Override
public void doRender(RenderMaterial material, int startVert, int endVert) {

    material.assign();

    for (VertexBufferImpl vb : vertexBuffers.valueCollection()) {
        vb.bind();
        GL20.glEnableVertexAttribArray(vb.getLayout());
        GL20.glVertexAttribPointer(vb.getLayout(), vb.getElements(), GL11.GL_FLOAT, false, 0, 0);
        //activeMaterial.getShader().enableAttribute(vb.getName(), vb.getElements(), GL11.GL_FLOAT, 0, 0, vb.getLayout());         
    }

    GL11.glDrawArrays(renderMode, startVert, endVert);

    for (VertexBufferImpl vb : vertexBuffers.valueCollection()) {
        GL20.glDisableVertexAttribArray(vb.getLayout());
    }

}

From source file:org.spout.engine.renderer.GL30BatchVertexRenderer.java

License:Open Source License

/**
 * Draws this batch/*  w  ww. j a va2  s  . c  o  m*/
 */
@Override
public void doRender(RenderMaterial material, int startVert, int endVert) {

    GL30.glBindVertexArray(vao);

    material.assign();

    for (VertexBufferImpl vb : vertexBuffers.valueCollection()) {
        vb.bind();
        GL20.glEnableVertexAttribArray(vb.getLayout());
        GL20.glVertexAttribPointer(vb.getLayout(), vb.getElements(), GL11.GL_FLOAT, false, 0, 0);
        //activeMaterial.getShader().enableAttribute(vb.getName(), vb.getElements(), GL11.GL_FLOAT, 0, 0, vb.getLayout());         
    }

    GL11.glDrawArrays(renderMode, startVert, endVert);

    for (VertexBufferImpl vb : vertexBuffers.valueCollection()) {
        GL20.glDisableVertexAttribArray(vb.getLayout());
    }

}

From source file:org.terasology.rendering.nui.internal.Line.java

License:Apache License

public void draw(float x1, float y1, float x2, float y2, float width, Color color, Color background,
        float alpha) {
    GL20.glUseProgram(0);/*from   w w  w  . jav  a  2  s.co  m*/
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);

    float t = 0;
    float r = 0;
    float f = width - (int) width;
    float a;
    boolean alphaBlend = alpha > 0;
    float cRed = color.rf();
    float cGreen = color.gf();
    float cBlue = color.bf();
    float bRed = background.rf();
    float bGreen = background.gf();
    float bBlue = background.bf();

    if (alphaBlend) {
        a = alpha;
    } else {
        a = 1.f;
    }

    if (width >= 0.0 && width < 1.0) {
        t = 0.05f;
        r = 0.48f + 0.32f * f;
        if (!alphaBlend) {
            cRed += 0.88 * (1 - f);
            cGreen += 0.88 * (1 - f);
            cBlue += 0.88 * (1 - f);
            if (cRed > 1.0f) {
                cRed = 1.0f;
            }
            if (cGreen > 1.0f) {
                cGreen = 1.0f;
            }
            if (cBlue > 1.0f) {
                cBlue = 1.0f;
            }
        } else {
            a *= f;
        }
    } else if (width >= 1.0 && width < 2.0) {
        t = 0.05f + f * 0.33f;
        r = 0.768f + 0.312f * f;
    } else if (width >= 2.0 && width < 3.0) {
        t = 0.38f + f * 0.58f;
        r = 1.08f;
    } else if (width >= 3.0 && width < 4.0) {
        t = 0.96f + f * 0.48f;
        r = 1.08f;
    } else if (width >= 4.0 && width < 5.0) {
        t = 1.44f + f * 0.46f;
        r = 1.08f;
    } else if (width >= 5.0 && width < 6.0) {
        t = 1.9f + f * 0.6f;
        r = 1.08f;
    } else if (width >= 6.0) {
        float ff = width - 6.0f;
        t = 2.5f + ff * 0.50f;
        r = 1.08f;
    }

    //determine angle of the line to horizontal
    float tx = 0; //core thinkness of a line
    float ty = 0;
    float rx = 0; //fading edge of a line
    float ry = 0;
    float cx = 0; //cap of a line
    float cy = 0;
    float epsilon = 0.01f;
    float dx = x2 - x1;
    float dy = y2 - y1;
    if (Math.abs(dx) < epsilon) {
        //vertical
        tx = t;
        ty = 0;
        rx = r;
        ry = 0;
        if (width > 0.0 && width < 1.0) {
            tx *= 8;
        } else if (width == 1.0) {
            tx *= 10;
        }
    } else if (Math.abs(dy) < epsilon) {
        //horizontal
        tx = 0;
        ty = t;
        rx = 0;
        ry = r;
        if (width > 0.0 && width < 1.0) {
            ty *= 8;
        } else if (width == 1.0) {
            ty *= 10;
        }
    } else {
        if (width < 3) { //approximate to make things even faster
            float m = dy / dx;
            //and calculate tx,ty,rx,ry
            if (m > -0.4142 && m <= 0.4142) {
                // -22.5< angle <= 22.5, approximate to 0 (degree)
                tx = t * 0.1f;
                ty = t;
                rx = r * 0.6f;
                ry = r;
            } else if (m > 0.4142 && m <= 2.4142) {
                // 22.5< angle <= 67.5, approximate to 45 (degree)
                tx = t * -0.7071f;
                ty = t * 0.7071f;
                rx = r * -0.7071f;
                ry = r * 0.7071f;
            } else if (m > 2.4142 || m <= -2.4142) {
                // 67.5 < angle <=112.5, approximate to 90 (degree)
                tx = t;
                ty = t * 0.1f;
                rx = r;
                ry = r * 0.6f;
            } else if (m > -2.4142 && m < -0.4142) {
                // 112.5 < angle < 157.5, approximate to 135 (degree)
                tx = t * 0.7071f;
                ty = t * 0.7071f;
                rx = r * 0.7071f;
                ry = r * 0.7071f;
            }
        } else { //calculate to exact
            dx = y1 - y2;
            dy = x2 - x1;
            float len = (float) Math.sqrt(dx * dx + dy * dy);
            dx /= len;
            dy /= len;
            cx = -0.6f * dy;
            cy = 0.6f * dx;
            tx = t * dx;
            ty = t * dy;
            rx = r * dx;
            ry = r * dy;
        }
    }

    //draw the line by triangle strip
    float[] lineVertex = { x1 - tx - rx, y1 - ty - ry, //fading edge1
            x2 - tx - rx, y2 - ty - ry, x1 - tx, y1 - ty, //core
            x2 - tx, y2 - ty, x1 + tx, y1 + ty, x2 + tx, y2 + ty, x1 + tx + rx, y1 + ty + ry, //fading edge2
            x2 + tx + rx, y2 + ty + ry };
    GL11.glVertexPointer(2, 0, wrap(lineVertex));

    if (!alphaBlend) {
        float[] lineColor = { bRed, bGreen, bBlue, bRed, bGreen, bBlue, cRed, cGreen, cBlue, cRed, cGreen,
                cBlue, cRed, cGreen, cBlue, cRed, cGreen, cBlue, bRed, bGreen, bBlue, bRed, bGreen, bBlue };
        GL11.glColorPointer(3, 0, wrap(lineColor));
    } else {
        float[] lineColor = { cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, a, cRed,
                cGreen, cBlue, a, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, 0, cRed,
                cGreen, cBlue, 0 };
        GL11.glColorPointer(4, 0, wrap(lineColor));
    }

    if ((Math.abs(dx) < epsilon || Math.abs(dy) < epsilon) && width <= 1.0) {
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 6);
    } else {
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 8);
    }

    //cap (do not draw if too thin)
    if (width >= 3) {
        //draw cap
        lineVertex = new float[] { x1 - rx + cx, y1 - ry + cy, //cap1
                x1 + rx + cx, y1 + ry + cy, x1 - tx - rx, y1 - ty - ry, x1 + tx + rx, y1 + ty + ry,
                x2 - rx - cx, y2 - ry - cy, //cap2
                x2 + rx - cx, y2 + ry - cy, x2 - tx - rx, y2 - ty - ry, x2 + tx + rx, y2 + ty + ry };
        GL11.glVertexPointer(2, 0, wrap(lineVertex));

        if (!alphaBlend) {
            float[] lineColor = { bRed, bGreen, bBlue, //cap1
                    bRed, bGreen, bBlue, cRed, cGreen, cBlue, cRed, cGreen, cBlue, bRed, bGreen, bBlue, //cap2
                    bRed, bGreen, bBlue, cRed, cGreen, cBlue, cRed, cGreen, cBlue };
            GL11.glColorPointer(3, 0, wrap(lineColor));
        } else {
            float[] lineColor = { cRed, cGreen, cBlue, 0, //cap1
                    cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue,
                    0, //cap2
                    cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, a };
            GL11.glColorPointer(4, 0, wrap(lineColor));
        }

        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 4, 4);
    }

    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
    GL11.glEnable(GL11.GL_CULL_FACE);

}

From source file:org.voxels.platform.LWJGLOpenGLAdapter.java

License:Open Source License

@Override
public void glDrawArrays(final int mode, final int first, final int count) {
    GL11.glDrawArrays(mode, first, count);
}