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");
  }
Example #2
0
  private void initProgram(GL3 gl3) {

    ShaderCode vertShader =
        ShaderCode.create(
            gl3,
            GL_VERTEX_SHADER,
            this.getClass(),
            SHADERS_ROOT,
            null,
            SHADERS_NAME,
            "vert",
            null,
            true);
    ShaderCode fragShader =
        ShaderCode.create(
            gl3,
            GL_FRAGMENT_SHADER,
            this.getClass(),
            SHADERS_ROOT,
            null,
            SHADERS_NAME,
            "frag",
            null,
            true);

    ShaderProgram shaderProgram = new ShaderProgram();
    shaderProgram.add(vertShader);
    shaderProgram.add(fragShader);

    shaderProgram.init(gl3);

    programName = shaderProgram.program();

    /**
     * These links don't go into effect until you link the program. If you want to change index, you
     * need to link the program again.
     */
    gl3.glBindAttribLocation(programName, Semantic.Attr.POSITION, "position");
    gl3.glBindAttribLocation(programName, Semantic.Attr.COLOR, "color");
    gl3.glBindFragDataLocation(programName, Semantic.Frag.COLOR, "outputColor");

    shaderProgram.link(gl3, System.out);
    /**
     * Take in account that JOGL offers a GLUniformData class, here we don't use it, but take a look
     * to it since it may be interesting for you.
     */
    modelToClipMatrixUL = gl3.glGetUniformLocation(programName, "modelToClipMatrix");

    vertShader.destroy(gl3);
    fragShader.destroy(gl3);

    checkError(gl3, "initProgram");
  }