Exemplo n.º 1
0
  private boolean initProgram(GL3 gl3) {

    boolean validated = true;

    ShaderCode[] shaderCodes = new ShaderCode[Shader.MAX];

    if (validated) {

      shaderCodes[Shader.VERT] =
          ShaderCode.create(
              gl3,
              GL_VERTEX_SHADER,
              this.getClass(),
              SHADERS_ROOT,
              null,
              SHADERS_SOURCE,
              "vert",
              null,
              true);
      shaderCodes[Shader.FRAG] =
          ShaderCode.create(
              gl3,
              GL_FRAGMENT_SHADER,
              this.getClass(),
              SHADERS_ROOT,
              null,
              SHADERS_SOURCE,
              "frag",
              null,
              true);

      ShaderProgram shaderProgram = new ShaderProgram();
      shaderProgram.add(shaderCodes[Shader.VERT]);
      shaderProgram.add(shaderCodes[Shader.FRAG]);

      shaderProgram.init(gl3);

      programName = shaderProgram.program();

      gl3.glBindAttribLocation(programName, Semantic.Attr.POSITION, "position");
      gl3.glBindAttribLocation(programName, Semantic.Attr.TEXCOORD, "texCoord");
      gl3.glBindFragDataLocation(programName, Semantic.Frag.COLOR, "color");

      shaderProgram.link(gl3, System.out);
    }
    if (validated) {

      gl3.glUniformBlockBinding(
          programName,
          gl3.glGetUniformBlockIndex(programName, "Transform"),
          Semantic.Uniform.TRANSFORM0);

      gl3.glUseProgram(programName);
      gl3.glUniform1i(gl3.glGetUniformLocation(programName, "diffuse"), 0);
      gl3.glUseProgram(0);
    }

    return validated & checkError(gl3, "initProgram");
  }
  public LitProgram(
      GL3 gl3,
      String shadersFilepath,
      String vertexShader,
      String fragmentShader,
      int projectionUBB) {

    super(gl3, shadersFilepath, vertexShader, fragmentShader);

    unLocModelToCameraMatrix = gl3.glGetUniformLocation(getProgramId(), "modelToCameraMatrix");
    unLocLightDiffuseIntensity = gl3.glGetUniformLocation(getProgramId(), "lightDiffuseIntensity");
    unLocLightAmbientIntensity = gl3.glGetUniformLocation(getProgramId(), "lightAmbientIntensity");

    unLocNormalModelToCameraMatrix =
        gl3.glGetUniformLocation(getProgramId(), "normalModelToCameraMatrix");
    unLocLightCameraSpacePosition =
        gl3.glGetUniformLocation(getProgramId(), "cameraSpaceLightPosition");
    unLocLightAttenuation = gl3.glGetUniformLocation(getProgramId(), "lightAttenuation");
    unLocShininessFactor = gl3.glGetUniformLocation(getProgramId(), "shininessFactor");
    unLocBaseDiffuseColor = gl3.glGetUniformLocation(getProgramId(), "baseDiffuseColor");

    int projectionUBI = gl3.glGetUniformBlockIndex(getProgramId(), "Projection");
    gl3.glUniformBlockBinding(getProgramId(), projectionUBI, projectionUBB);
  }