private boolean initVertexBuffer(GL4 gl4) { gl4.glGenBuffers(Buffer.MAX.ordinal(), bufferName, 0); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName[Buffer.ELEMENT.ordinal()]); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName[Buffer.F64.ordinal()]); DoubleBuffer positionBuffer = GLBuffers.newDirectDoubleBuffer(positionData); gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); return checkError(gl4, "initArrayBuffer"); }
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; FloatUtil.makePerspective( projection, 0, true, (float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); view = view(); FloatUtil.makeIdentity(model); FloatUtil.multMatrix(projection, view); FloatUtil.multMatrix(projection, model); for (int i = 0; i < projection.length; i++) { mvp[i] = projection[i]; } gl4.glProgramUniformMatrix4dv( programName[Program.VERT.ordinal()], uniformMvp, 1, false, mvp, 0); gl4.glProgramUniform4dv( programName[Program.FRAG.ordinal()], uniformDiffuse, 1, new double[] {1.0f, 0.5f, 0.0f, 1.0f}, 0); gl4.glViewportIndexedfv(0, new float[] {0, 0, windowSize.x, windowSize.y}, 0); gl4.glClearBufferfv(GL_COLOR, 0, new float[] {0.0f, 0.0f, 0.0f, 0.0f}, 0); gl4.glBindProgramPipeline(pipelineName[0]); gl4.glBindVertexArray(vertexArrayName[0]); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName[Buffer.ELEMENT.ordinal()]); gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); return true; }