コード例 #1
0
  @Override
  protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    // Setup blending
    gl3.glEnable(GL_BLEND);
    gl3.glBlendEquation(GL_FUNC_ADD);
    gl3.glBlendFunc(GL_ONE, GL_SRC1_COLOR);

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1));

    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformDiffuse, 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

    return true;
  }
コード例 #2
0
  @Override
  protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Mat4 projection = glm.ortho_(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(new Mat4(1.0f)).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_RECTANGLE, textureRectName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

    return true;
  }
コード例 #3
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");
  }