Java Code Examples for com.jogamp.opengl.GL3#glDrawElements()

The following examples show how to use com.jogamp.opengl.GL3#glDrawElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TriangleBatch.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Draw the triangles.
 * <p>
 * Make sure you call glEnableClientState for these arrays.
 *
 * @param gl the current OpenGL context.
 */
public void draw(final GL3 gl) {
    gl.glBindVertexArray(vertexArrayBufferObject[0]);

    gl.glDrawElements(GL3.GL_TRIANGLES, nNumIndexes, GL3.GL_UNSIGNED_SHORT, 0);

    // Unbind to anybody
    // Should this be just plain 0?
    //	gl.glBindVertexArray(vertexArrayBufferObject[0]);
    gl.glBindVertexArray(0);
}
 
Example 2
Source File: Gl_320_draw_range_elements.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, windowSize.x / 3.0f / windowSize.y, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);

        pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);

    float[] depth = {1.0f};
    gl3.glClearBufferfv(GL_DEPTH, 0, depth, 0);
    gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0);

    gl3.glUseProgram(programName);

    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glViewport(windowSize.x * 0 / 3, 0, windowSize.x / 3, windowSize.y);
    gl3.glDrawElements(GL_TRIANGLES, elementCount / 2, GL_UNSIGNED_SHORT, 0);

    gl3.glViewport(windowSize.x * 1 / 3, 0, windowSize.x / 3, windowSize.y);
    gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount / 2,
            GL_UNSIGNED_SHORT, Short.BYTES * elementCount / 2, 1, 0);

    gl3.glViewport(windowSize.x * 2 / 3, 0, windowSize.x / 3, windowSize.y);
    gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount / 2, GL_UNSIGNED_SHORT, 0, 1, vertexCount / 2);

    return true;
}