Beispiel #1
0
  @Override
  public void init() {
    shaderProgram.init(gl);
    shaderProgram.bind();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClearDepth(1.0f);

    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glEnable(GL.GL_CULL_FACE);

    projectionMatrix.init(gl, shaderProgram.getUniformLocation("u_projectionMatrix"));

    modelViewMatrix.init(gl, shaderProgram.getUniformLocation("u_modelViewMatrix"));
    inverseViewMatrix.init(gl, shaderProgram.getUniformLocation("u_inverseViewMatrix"));

    normalMatrix.init(gl, shaderProgram.getUniformLocation("u_normalMatrix"));

    cubeMap.init(gl, shaderProgram.getUniformLocation("u_cubemapTexture"));

    model.init(
        gl,
        shaderProgram.getAttribLocation("a_position"),
        shaderProgram.getAttribLocation("a_normal"));

    // View Matrix
    viewMatrix.loadIdentity();
    viewMatrix.lookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
  }
Beispiel #2
0
  @Override
  public void display() {
    gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);

    // Calculate the model matrix ...
    modelMatrix.loadIdentity();
    // ... by rotating the cube.
    modelMatrix.rotate(Maths.degToRad(15), new float[] {1, 0, 0});
    modelMatrix.rotate(Maths.degToRad(angle), new float[] {0, 1, 0});

    // MV = V * M
    modelViewMatrix.multiply(viewMatrix, modelMatrix);
    modelViewMatrix.bind();

    // Again, extract the normal matrix.
    // Remember, so far the model view matrix (rotation part) is orthogonal.
    normalMatrix.extract(modelViewMatrix);
    normalMatrix.bind();

    // Extract the rotation part of the view matrix.
    inverseViewMatrix.extract(viewMatrix);

    // Pass this matrix to the shader with the transpose flag.
    // As the view matrix is orthogonal, the transposed is the inverse view matrix.
    inverseViewMatrix.bind(true);

    cubeMap.bind();

    model.bind();
    model.draw(GL3.GL_TRIANGLES);

    gl.glFlush();

    update();
  }
Beispiel #3
0
  @Override
  public void reshape(final int x, final int y, final int width, final int height) {
    gl.glViewport(0, 0, width, height);

    // Projection Matrix
    projectionMatrix.loadIdentity();
    projectionMatrix.perspective(40f, aspect, 1.0f, 100.0f);
    projectionMatrix.bind();
  }