Java 类org.lwjgl.opengl.ARBFragmentShader 实例源码

项目:NeoTextureEdit2    文件:OpenGLTextureRenderCanvas.java   
/**
 * Loads a vertex and fragment shader pair, compiles them and links them to a ProgramObjectARB
 * @param name
 * @return the program object ID
 */
public int getShaderProgram(ByteBuffer vcode, ByteBuffer fcode) {
    int progID = -1;

    int vid = ARBShaderObjects.glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB);
    int fid = ARBShaderObjects.glCreateShaderObjectARB(ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);

    ARBShaderObjects.glShaderSourceARB(vid, vcode);
    ARBShaderObjects.glCompileShaderARB(vid);
    printLogInfo(vid, "Compile Vertex Shader");

    ARBShaderObjects.glShaderSourceARB(fid, fcode);
    ARBShaderObjects.glCompileShaderARB(fid);
    printLogInfo(fid, "Compile Fragment Shader");

    progID = ARBShaderObjects.glCreateProgramObjectARB();
    ARBShaderObjects.glAttachObjectARB(progID, vid);
    ARBShaderObjects.glAttachObjectARB(progID, fid);

    ARBShaderObjects.glLinkProgramARB(progID);
    printLogInfo(progID, "Link");
    ARBShaderObjects.glValidateProgramARB(progID);
    printLogInfo(progID, "Validate");

    return progID;
}
项目:DynamicSurroundings    文件:ShaderProgram.java   
protected void initialize(final String vertexSrc, final String fragmentSrc) throws ShaderException {

        int vertShader = 0;
        int fragShader = 0;

        vertShader = createShader(vertexSrc, ARBVertexShader.GL_VERTEX_SHADER_ARB);
        fragShader = createShader(fragmentSrc, ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);

        if (vertShader == 0 || fragShader == 0)
            throw new ShaderException(this.name, "Unable to intialize shader!");

        this.programId = ARBShaderObjects.glCreateProgramObjectARB();

        if (this.programId != 0) {
            ARBShaderObjects.glAttachObjectARB(this.programId, vertShader);
            ARBShaderObjects.glAttachObjectARB(this.programId, fragShader);

            ARBShaderObjects.glLinkProgramARB(this.programId);
            if (ARBShaderObjects.glGetObjectParameteriARB(this.programId,
                    ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) {
                throw new ShaderException(this.name, getLogInfo(this.programId));
            }

            ARBShaderObjects.glValidateProgramARB(this.programId);
            if (ARBShaderObjects.glGetObjectParameteriARB(this.programId,
                    ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) {
                throw new ShaderException(this.name, getLogInfo(this.programId));
            }
        }
    }
项目:DynamicSurroundings    文件:ShaderUtils.java   
public static int createProgram(@Nullable final ResourceLocation vert, @Nullable final ResourceLocation frag) {
    int vertId = 0, fragId = 0, program;
    if (vert != null)
        vertId = createShader(vert, ARBVertexShader.GL_VERTEX_SHADER_ARB);
    if (frag != null)
        fragId = createShader(frag, ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);

    program = OpenGlHelper.glCreateProgram();
    if (program == 0)
        return 0;

    if (vert != null)
        OpenGlHelper.glAttachShader(program, vertId);
    if (frag != null)
        OpenGlHelper.glAttachShader(program, fragId);

    OpenGlHelper.glLinkProgram(program);
    if (OpenGlHelper.glGetProgrami(program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) {
        LibLog.log().error(getLogInfoProgram(program), null);
        return 0;
    }

    GL20.glValidateProgram(program);
    if (OpenGlHelper.glGetProgrami(program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) {
        LibLog.log().error(getLogInfoProgram(program), null);
        return 0;
    }

    OpenGlHelper.glDeleteShader(vertId);
    OpenGlHelper.glDeleteShader(fragId);

    OpenGlHelper.glUseProgram(0);

    return program;
}
项目:Beeg-StaKe    文件:Shader.java   
public Shader(String fragmentShader, String vertexShader) {
    this.fragmentShader = fragmentShader;
    this.vertexShader = vertexShader;
    this.vertexShaderId = loadShader(ARBVertexShader.GL_VERTEX_SHADER_ARB,
            vertexShader);
    this.fragmentShaderId = loadShader(
            ARBFragmentShader.GL_FRAGMENT_SHADER_ARB, fragmentShader);
    this.programId = ARBShaderObjects.glCreateProgramObjectARB();
    ARBShaderObjects.glAttachObjectARB(this.programId, this.vertexShaderId);
    ARBShaderObjects.glAttachObjectARB(this.programId,
            this.fragmentShaderId);
    ARBShaderObjects.glLinkProgramARB(this.programId);
    ARBShaderObjects.glValidateProgramARB(this.programId);
}
项目:example-jovr-lwjgl3-rift    文件:ShaderProgram120.java   
public void init() {
    // vertex shader
    final int vertShader = ARBShaderObjects.glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB);
    if (vertShader == GL_FALSE) {
        throw new RuntimeException("failed to create vert shader");
    }
    final String vertexCode = ""
            + "#version 120                                                 \n"
            + "                                                             \n" 
            + "                                                             \n" 
            + "void main() {                                                \n" 
            //+ "    gl_Position = gl_Vertex;                                 \n"
            + "    gl_Position = vec4(gl_Vertex.xyz * 0.5, gl_Vertex.w);    \n"
            + "}                                                            \n";
    ARBShaderObjects.glShaderSourceARB(vertShader, vertexCode);
    ARBShaderObjects.glCompileShaderARB(vertShader);
    if (GL20.glGetShaderi(vertShader, GL20.GL_COMPILE_STATUS) == GL_FALSE) {
        System.out.println(GL20.glGetShaderInfoLog(vertShader));
        throw new RuntimeException("vert comp failed");
    }

    // fragment shader
    final int fragShader = ARBShaderObjects.glCreateShaderObjectARB(ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
    if (fragShader == GL_FALSE) {
        throw new RuntimeException("failed to create frag shader");
    }
    final String fragCode = ""
            + "#version 120                                     \n"
            + "                                                 \n" 
            + "void main() {                                    \n" 
            + "    gl_FragColor = vec4(1.0, 1.0, 0.4, 1.0);     \n"
            + "}                                                \n";
    ARBShaderObjects.glShaderSourceARB(fragShader, fragCode);
    ARBShaderObjects.glCompileShaderARB(fragShader);
    if (GL20.glGetShaderi(fragShader, GL20.GL_COMPILE_STATUS) == GL_FALSE) {
        System.out.println(GL20.glGetShaderInfoLog(fragShader));
        throw new RuntimeException("frag comp failed");
    }

    // program
    program = ARBShaderObjects.glCreateProgramObjectARB();
    if (program == GL_FALSE) {
        throw new RuntimeException("failed to create shader program");
    }
    ARBShaderObjects.glAttachObjectARB(program, vertShader);
    ARBShaderObjects.glAttachObjectARB(program, fragShader);
    ARBShaderObjects.glLinkProgramARB(program);                     //is there a way to check this result?
    ARBShaderObjects.glValidateProgramARB(program);                 //is there a way to check this result?

    glClearColor(.42f, .67f, .87f, 1f);
}
项目:PenguinMenaceEngine    文件:Shader.java   
/**
 * Create a shader with the given id and shader strings.
 *
 * @param vsh The vertex shader. (as a string)
 * @param fsh The fragment shader. (as a string)
 */
public Shader(final String vsh, final String fsh) {
    if (!Display.isCreated()) {
        throw new IllegalStateException("You need to initialize the display module first.");
    }
    try {
        if (vsh != null) {
            vsId = createShader(vsh, ARBVertexShader.GL_VERTEX_SHADER_ARB);
        }
        if (fsh != null) {
            fsId = createShader(fsh,
                    ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
        }
        program = ARBShaderObjects.glCreateProgramObjectARB();

        if (program <= 0) {
            throw new RuntimeException("Cannot create shader");
        }

        if (vsId != 0) {
            ARBShaderObjects.glAttachObjectARB(program, vsId);
        }
        if (fsId != 0) {
            ARBShaderObjects.glAttachObjectARB(program, fsId);
        }
        ARBShaderObjects.glLinkProgramARB(program);

        if (ARBShaderObjects.glGetObjectParameteriARB(program,
                ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) {
            throw new RuntimeException(getLogInfo(program));
        }

        ARBShaderObjects.glValidateProgramARB(program);
        if (ARBShaderObjects.glGetObjectParameteriARB(program,
                ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) {
            throw new RuntimeException(getLogInfo(program));
        }
    } catch (RuntimeException e) {
        delete();
        throw e;
    }
}