예제 #1
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");
  }
예제 #2
0
  @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;
  }
예제 #3
0
 public void makePmvMatrix() {
   FloatUtil.multMatrixf(pmvMatrix.glGetPMatrixf(), pmvMatrix.glGetMvMatrixf(), mvp, 0);
   getMatrix4f(pmvMatrix.glGetPMatrixf())
       .mul(getMatrix4f(pmvMatrix.glGetMvMatrixf()))
       .writeToBuffer(pmv, true, false);
 }
예제 #4
0
 /**
  * Send uniform matrices "ProjectionMatrix, ModelViewMatrix and ModelViewProjectionMatrix" to
  * vertex shader
  *
  * @param pmvMatrix the PMVMatrix containing all matrices
  */
 public void setPMVMatrix(PMVMatrix pmvMatrix) {
   FloatBuffer pmvMat = FloatBuffer.allocate(16);
   FloatUtil.multMatrixf(pmvMatrix.glGetPMatrixf(), pmvMatrix.glGetMvMatrixf(), pmvMat);
   gl.glUniformMatrix4fv(this.getModelViewProjectionMatrixID(), 1, false, pmvMat);
 }