@Override
  public void display(GLAutoDrawable glad) {
    System.out.println("display");

    GL3 gl3 = glad.getGL().getGL3();

    gl3.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl3.glClear(GL3.GL_COLOR_BUFFER_BIT);

    programObject.bind(gl3);
    {
      programObject.setUniform(gl3, "offset", new float[] {0.5f, 0.5f}, 2);

      gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBufferObject[0]);

      gl3.glEnableVertexAttribArray(0);
      gl3.glEnableVertexAttribArray(1);
      {
        gl3.glVertexAttribPointer(0, 4, GL3.GL_FLOAT, false, 0, 0);
        gl3.glVertexAttribPointer(1, 4, GL3.GL_FLOAT, false, 0, 36 * 4 * 4);

        gl3.glDrawArrays(GL3.GL_TRIANGLES, 0, 36);
      }
      gl3.glDisableVertexAttribArray(0);
      gl3.glDisableVertexAttribArray(1);
    }
    programObject.unbind(gl3);

    glad.swapBuffers();
  }
Esempio n. 2
0
    private void displayVBOOnly(final GL3 gl) {
      final int posLoc = gl.glGetAttribLocation(progID, "vPosition");
      final int colorLoc = gl.glGetAttribLocation(progID, "vColor");
      gl.glEnableVertexAttribArray(posLoc);
      gl.glEnableVertexAttribArray(colorLoc);

      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo);
      final int stride = 6 * Buffers.SIZEOF_FLOAT;
      final int cOff = 3 * Buffers.SIZEOF_FLOAT;
      gl.glVertexAttribPointer(posLoc, 3, GL3.GL_FLOAT, false, stride, 0L);
      gl.glVertexAttribPointer(colorLoc, 3, GL3.GL_FLOAT, false, stride, cOff);
      gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, ibo);
      gl.glDrawElements(GL3.GL_TRIANGLES, 3, GL3.GL_UNSIGNED_SHORT, 0L);

      gl.glDisableVertexAttribArray(posLoc);
      gl.glDisableVertexAttribArray(colorLoc);
      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
      gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, 0);
    }