Esempio n. 1
0
  @Override
  public void display(GLAutoDrawable glad) {
    GL3 gl3 = glad.getGL().getGL3();

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

    gl3.glUseProgram(program);

    gl3.glBindVertexArray(VAO[0]);
    gl3.glDrawArrays(GL3.GL_TRIANGLES, 0, 3);
    gl3.glBindVertexArray(0);

    gl3.glUseProgram(0);
  }
Esempio n. 2
0
  @Override
  public void display(GLAutoDrawable drawable) {
    //        System.out.println("display");

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

    /**
     * We set the clear color and depth (although depth is not necessary since it is 1 by default).
     */
    gl3.glClearColor(0f, .33f, 0.66f, 1f);
    gl3.glClearDepthf(1f);
    gl3.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    {
      // update matrix based on time
      now = System.currentTimeMillis();
      float diff = (float) (now - start) / 1000;
      /**
       * Here we build the matrix that will multiply our original vertex positions. We scale,
       * halving it, and rotate it.
       */
      scale = FloatUtil.makeScale(scale, true, 0.5f, 0.5f, 0.5f);
      zRotazion = FloatUtil.makeRotationEuler(zRotazion, 0, 0, 0, diff);
      modelToClip = FloatUtil.multMatrix(scale, zRotazion);
    }
    gl3.glUseProgram(programName);
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glUniformMatrix4fv(modelToClipMatrixUL, 1, false, modelToClip, 0);

    gl3.glDrawElements(GL_TRIANGLES, elementSize, GL_UNSIGNED_SHORT, 0);
    /**
     * The following line binds VAO and program to the default values, this is not a cheaper
     * binding, it costs always as a binding. Every binding means additional validation and
     * overhead, this may affect your performances. So you should avoid these calls, but remember
     * that OpenGL is a state machine, so what you left bound remains bound!
     */
    //        gl3.glBindVertexArray(0);
    //        gl3.glUseProgram(0);
    /**
     * Check always any GL error, but keep in mind this is an implicit synchronization between CPU
     * and GPU, so you should use it only for debug purposes.
     */
    checkError(gl3, "display");
  }