Exemplo n.º 1
0
 public boolean initShader() {
   int vertShader = 0, fragShader = 0;
   try {
     vertShader = this.createShader("./shaders/screen.vert", ARBVertexShader.GL_VERTEX_SHADER_ARB);
     fragShader =
         this.createShader("./shaders/screen.frag", ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
   } catch (final Exception exc) {
     exc.printStackTrace();
     return false;
   } finally {
     if ((vertShader == 0) || (fragShader == 0)) {
       return false;
     }
   }
   this.program = ARBShaderObjects.glCreateProgramObjectARB();
   if (this.program == 0) {
     return false;
   }
   ARBShaderObjects.glAttachObjectARB(this.program, vertShader);
   ARBShaderObjects.glAttachObjectARB(this.program, fragShader);
   ARBShaderObjects.glLinkProgramARB(this.program);
   if (ARBShaderObjects.glGetObjectParameteriARB(
           this.program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB)
       == GL11.GL_FALSE) {
     System.err.println(this.getLogInfo(this.program));
     return false;
   }
   ARBShaderObjects.glValidateProgramARB(this.program);
   if (ARBShaderObjects.glGetObjectParameteriARB(
           this.program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB)
       == GL11.GL_FALSE) {
     System.err.println(this.getLogInfo(this.program));
     return false;
   }
   return true;
 }
Exemplo n.º 2
0
  private int createShader(final String filename, final int shaderType) throws Exception {
    int shader = 0;
    try {
      shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);

      if (shader == 0) {
        return 0;
      }

      ARBShaderObjects.glShaderSourceARB(shader, this.readFileAsString(filename));
      ARBShaderObjects.glCompileShaderARB(shader);
      if (ARBShaderObjects.glGetObjectParameteriARB(
              shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB)
          == GL11.GL_FALSE) {
        throw new RuntimeException("Error creating shader: " + this.getLogInfo(shader));
      }
      return shader;
    } catch (final Exception exc) {
      ARBShaderObjects.glDeleteObjectARB(shader);
      throw exc;
    }
  }
Exemplo n.º 3
0
 private String getLogInfo(final int obj) {
   return ARBShaderObjects.glGetInfoLogARB(
       obj,
       ARBShaderObjects.glGetObjectParameteriARB(
           obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB));
 }