private boolean initBuffer(GL3 gl3) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl3.glGenBuffers(Buffer.MAX, bufferName); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW); gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(vertexBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return checkError(gl3, "initBuffer"); }
@Override public void init(GLAutoDrawable glad) { GL3 gl3 = glad.getGL().getGL3(); try { shaders.add( GLSLHelpers.createShader(gl3, getClass(), GL3.GL_VERTEX_SHADER, "glsl/simple_vs")); shaders.add( GLSLHelpers.createShader(gl3, getClass(), GL3.GL_FRAGMENT_SHADER, "glsl/simple_fs")); program = GLSLHelpers.createProgram(gl3, shaders); gl3.glGenVertexArrays(1, VAO, 0); gl3.glBindVertexArray(VAO[0]); gl3.glGenBuffers(1, VBO, 0); gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, VBO[0]); FloatBuffer buffer = GLBuffers.newDirectFloatBuffer(TRIANGLE); gl3.glBufferData(GL3.GL_ARRAY_BUFFER, buffer.capacity() * 4, buffer, GL3.GL_STATIC_DRAW); gl3.glEnableVertexAttribArray(0); gl3.glVertexAttribPointer(0, 2, GL3.GL_FLOAT, false, 0, 0); gl3.glBindVertexArray(0); } catch (Throwable t) { t.printStackTrace(); } }
private boolean initBuffer(GL3 gl3) { FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl3.glGenBuffers(1, bufferName); gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0)); gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); BufferUtils.destroyDirectBuffer(vertexBuffer); return checkError(gl3, "initBuffer"); }
private void initBuffers(GL3 gl3) { FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); gl3.glGenBuffers(Buffer.MAX, bufferName); gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); { gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); } gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); { gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); } gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); BufferUtils.destroyDirectBuffer(vertexBuffer); BufferUtils.destroyDirectBuffer(elementBuffer); checkError(gl3, "initBuffers"); }