Beispiel #1
0
  @Override
  public void display() {

    gl.glClear(GL4.GL_COLOR_BUFFER_BIT | GL4.GL_DEPTH_BUFFER_BIT);

    // Initialize with the identity matrix ...
    modelMatrix.loadIdentity();

    // Create the view matrix.
    viewMatrix.loadIdentity();
    viewMatrix.lookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    // The calculations are done in camera / view space.
    // So pass the view matrix, which is a rigid body transform.
    normalMatrix.extract(viewMatrix);

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

    modelViewMatrix.bind();
    normalMatrix.bind();

    light.setDirOrPos(Matrix4.multiplyVector3(viewMatrix.getMatrix(), light.getDirOrPos()));

    light.bind();
    material.bind();

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

    gl.glFlush();
  }
Beispiel #2
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"));
    normalMatrix.init(gl, shaderProgram.getUniformLocation("u_normalMatrix"));

    light.init(
        gl,
        shaderProgram.getUniformLocation("u_light.direction"),
        shaderProgram.getUniformLocation("u_light.ambientColor"),
        shaderProgram.getUniformLocation("u_light.diffuseColor"),
        shaderProgram.getUniformLocation("u_light.specularColor"));

    material.init(
        gl,
        shaderProgram.getUniformLocation("u_material.ambientColor"),
        shaderProgram.getUniformLocation("u_material.diffuseColor"),
        shaderProgram.getUniformLocation("u_material.specularColor"),
        shaderProgram.getUniformLocation("u_material.specularExponent"));

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