Esempio n. 1
0
    private int initVAO(GL3 gl) {
      int[] buff = new int[1];
      gl.glGenVertexArrays(1, buff, 0);
      int vao = buff[0];
      Assert.assertTrue("Invalid VAO: " + vao, vao > 0);

      gl.glUseProgram(progID);
      final int posLoc = gl.glGetAttribLocation(progID, "vPosition");
      final int colorLoc = gl.glGetAttribLocation(progID, "vColor");
      gl.glUseProgram(0);

      gl.glBindVertexArray(vao);
      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo);
      gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, ibo);

      gl.glEnableVertexAttribArray(posLoc);
      gl.glEnableVertexAttribArray(colorLoc);

      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.glBindVertexArray(0);
      // See class documentation above!
      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
      gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, 0);
      return vao;
    }
 /**
  * Activate and use a given shader.
  *
  * @param s the shader to be activated
  */
 @Override
 public void useShader(Shader s) {
   if (s != null) {
     activeShaderID = ((GLShader) s).programId();
     gl.glUseProgram(activeShaderID);
   }
 }
  /** This method is called at the beginning of each frame, i.e., before scene drawing starts. */
  private void beginFrame() {
    // Set the active shader as default for this frame
    gl.glUseProgram(activeShaderID);

    // Clear color and depth buffer for the new frame
    gl.glClear(GL3.GL_COLOR_BUFFER_BIT);
    gl.glClear(GL3.GL_DEPTH_BUFFER_BIT);
  }