Example usage for org.lwjgl.opengl GL20 GL_FRAGMENT_SHADER

List of usage examples for org.lwjgl.opengl GL20 GL_FRAGMENT_SHADER

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 GL_FRAGMENT_SHADER.

Prototype

int GL_FRAGMENT_SHADER

To view the source code for org.lwjgl.opengl GL20 GL_FRAGMENT_SHADER.

Click Source Link

Document

Accepted by the type argument of CreateShader and returned by the params parameter of GetShaderiv.

Usage

From source file:de.ikosa.mars.viewer.glviewer.engine.GLHardcodedShader.java

License:Open Source License

private static GLShader createTexturedShader() {
    int vertexShaderId = compileShader(texturedVertexShaderSource, GL20.GL_VERTEX_SHADER);
    int fragmentShaderId = compileShader(texturedFragmentShaderSource, GL20.GL_FRAGMENT_SHADER);

    int programId = GL20.glCreateProgram();
    GL20.glAttachShader(programId, vertexShaderId);
    GL20.glAttachShader(programId, fragmentShaderId);

    // Bind Attrib Location...
    GL20.glBindAttribLocation(programId, 0, "in_Position");
    GL20.glBindAttribLocation(programId, 1, "in_Normal");
    GL20.glBindAttribLocation(programId, 2, "in_TexCoord");

    GL20.glLinkProgram(programId);/*from   w  ww . j a  va  2s .c o  m*/

    validateLinkage(programId);

    GL20.glValidateProgram(programId);

    return new GLShader(programId, vertexShaderId, fragmentShaderId);
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLHardcodedShader.java

License:Open Source License

private static GLShader createFlatShader() {
    int vertexShaderId = compileShader(flatVertexShaderSource, GL20.GL_VERTEX_SHADER);
    int fragmentShaderId = compileShader(flatFragmentShaderSource, GL20.GL_FRAGMENT_SHADER);

    int programId = GL20.glCreateProgram();
    GL20.glAttachShader(programId, vertexShaderId);
    GL20.glAttachShader(programId, fragmentShaderId);

    // Bind Attrib Location...
    GL20.glBindAttribLocation(programId, 0, "in_Position");
    GL20.glBindAttribLocation(programId, 1, "in_Normal");

    GL20.glLinkProgram(programId);/*from  w  ww.  jav a 2 s  . co m*/

    validateLinkage(programId);

    GL20.glValidateProgram(programId);

    return new GLShader(programId, vertexShaderId, fragmentShaderId);
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLShaderBuilder.java

License:Open Source License

public GLShader createShader(GLResources resourceManager) {
    int vertexShaderId = compileShader(vertexSource, GL20.GL_VERTEX_SHADER);
    int fragmentShaderId = compileShader(fragmentSource, GL20.GL_FRAGMENT_SHADER);

    int programId = GL20.glCreateProgram();
    GL20.glAttachShader(programId, vertexShaderId);
    GL20.glAttachShader(programId, fragmentShaderId);

    // Bind attribute locations
    GL20.glBindAttribLocation(programId, 0, "in_Position");

    if (vertexSource.contains("in_Normal"))
        GL20.glBindAttribLocation(programId, 1, "in_Normal");
    if (vertexSource.contains("in_TexCoord"))
        GL20.glBindAttribLocation(programId, 2, "in_TexCoord");

    GL20.glLinkProgram(programId);//w  ww  .j  a va2s .c  om

    validateLinkage(programId);

    GL20.glValidateProgram(programId);

    return new GLShader(programId, vertexShaderId, fragmentShaderId);
}

From source file:engine.render.Shader.AbstractShader.java

private void createProgram(String VertexShaderFilePath, String fragmenShaderFilePath) {
    programID = GL20.glCreateProgram();/*from ww  w. ja  v  a  2 s  .  c  om*/
    vsid = loadShader(VertexShaderFilePath, GL20.GL_VERTEX_SHADER);
    fsid = loadShader(fragmenShaderFilePath, GL20.GL_FRAGMENT_SHADER);
}

From source file:eu.over9000.veya.rendering.Program.java

License:Open Source License

public Program(final String shaderName, final String[] uniformNames) {
    final int vsID = Program.loadShader(
            Program.class.getResourceAsStream("/shaders/" + shaderName + "/vertex.glsl"),
            GL20.GL_VERTEX_SHADER);//from  w  ww .j a  va2 s .com
    final int fsID = Program.loadShader(
            Program.class.getResourceAsStream("/shaders/" + shaderName + "/fragment.glsl"),
            GL20.GL_FRAGMENT_SHADER);

    this.id = GL20.glCreateProgram();
    GL20.glAttachShader(this.id, vsID);
    GL20.glAttachShader(this.id, fsID);

    GL20.glLinkProgram(this.id);
    Program.checkLinkage(this.id);

    //GL20.glValidateProgram(this.id);
    //Program.checkValidation(this.id);

    GL20.glDetachShader(this.id, vsID);
    GL20.glDetachShader(this.id, fsID);

    GL20.glDeleteShader(vsID);
    GL20.glDeleteShader(fsID);

    this.uniformLocations = new HashMap<>(uniformNames.length + 1, 1);
    for (final String name : uniformNames) {
        final int loc = GL20.glGetUniformLocation(this.id, name);
        this.uniformLocations.put(name, loc);
        System.out.println("UniformLoc for " + name + "=" + loc);
    }

    Util.checkGLError();
}

From source file:fr.guillaume.prive.viper.core.graphic.GraphicMotor.java

private static void setupShaders() {
    int vsId = GraphicMotor.loadShader("resources/shader/ship.vert", GL20.GL_VERTEX_SHADER);
    int fsId = GraphicMotor.loadShader("resources/shader/ship.frag", GL20.GL_FRAGMENT_SHADER);

    instance.shipShaderId = GL20.glCreateProgram();
    GL20.glAttachShader(instance.shipShaderId, vsId);
    GL20.glAttachShader(instance.shipShaderId, fsId);
    GL20.glBindAttribLocation(instance.shipShaderId, 0, "in_Position");
    GL20.glBindAttribLocation(instance.shipShaderId, 1, "Normal");
    GL20.glBindAttribLocation(instance.shipShaderId, 2, "in_Color");
    GL20.glBindAttribLocation(instance.shipShaderId, 3, "in_TextureCoord");

    GL20.glLinkProgram(instance.shipShaderId);
    GL20.glValidateProgram(instance.shipShaderId);

    instance.projectionMatrixLocation = GL20.glGetUniformLocation(instance.shipShaderId, "projectionMatrix");
    instance.viewMatrixLocation = GL20.glGetUniformLocation(instance.shipShaderId, "viewMatrix");
    instance.modelMatrixLocation = GL20.glGetUniformLocation(instance.shipShaderId, "modelMatrix");

    instance.useTextureLocation = GL20.glGetUniformLocation(instance.shipShaderId, "use_texture");

    GraphicMotor.exitOnGLError("setupShaders");
}

From source file:fr.ign.cogit.geoxygene.appli.gl.program.BlendingModeGLProgramBuilder.java

License:Open Source License

@Override
public void preBuildActions(GLProgram program) {

    try {//from  w  w  w .  j  a  v  a 2 s .c  o  m
        Shader vmainshader = new Shader("screenspace.vert", GL20.GL_VERTEX_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./screenspace.vert.glsl").toURL());
        Shader vsubshader = new Shader("identity.vert", GL20.GL_VERTEX_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./identity.vert.glsl").toURL());

        String blending_mode_name = "blending-" + this.mode.toString().toLowerCase() + ".frag";
        Shader fmainshader = new Shader(blending_mode_name, GL20.GL_FRAGMENT_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./" + blending_mode_name + ".glsl")
                        .toURL());
        String filter_name = "filter";
        if (this.filter instanceof LayerFilterContrast)
            filter_name += "Contrast.frag";
        else
            filter_name += "Identity.frag";
        Shader fsubshader = new Shader(filter_name, GL20.GL_FRAGMENT_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./" + filter_name + ".glsl").toURL());
        program.addShader(vmainshader);
        program.addShader(vsubshader);
        program.addShader(fmainshader);
        program.addShader(fsubshader);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:fr.ign.cogit.geoxygene.appli.gl.program.ScreenspaceAntialiasedTextureGLProgramBuilder.java

License:Open Source License

@Override
public void preBuildActions(GLProgram program) {
    try {/*w  w  w  .jav  a 2 s  .  c om*/

        Shader vmainshader = new Shader("screenspace.vert", GL20.GL_VERTEX_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./screenspace.vert.glsl").toURL());

        Shader fmainshader = new Shader("antialiased.frag", GL20.GL_FRAGMENT_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./antialiased.frag.glsl").toURL());
        Shader fsubshader = new Shader("filteridentity.frag", GL20.GL_FRAGMENT_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./filterIdentity.frag.glsl").toURL());

        program.addShader(vmainshader);
        program.addShader(fmainshader);
        program.addShader(fsubshader);
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }

}

From source file:fr.ign.cogit.geoxygene.appli.gl.program.WorldspaceColorGLProgramBuilder.java

License:Open Source License

@Override
public void preBuildActions(GLProgram colorProgram) {

    try {//from  w  w w  .  ja  va2s  . c o m

        Shader vmainshader = new Shader("world2screenspace.vert", GL20.GL_VERTEX_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./world2screenspace.vert.glsl").toURL());
        Shader vsubshader = new Shader("identity.vert", GL20.GL_VERTEX_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./identity.vert.glsl").toURL());

        Shader fmainshader = new Shader("polygon.color.frag", GL20.GL_FRAGMENT_SHADER,
                Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI().resolve("./polygon.color.frag.glsl").toURL());

        colorProgram.addShader(vmainshader);
        colorProgram.addShader(vsubshader);
        colorProgram.addShader(fmainshader);

        //            ShaderDescriptor vertexshader = (ShaderDescriptor) ResourcesManager.Root().getSubManager(GeoxygeneConstants.GEOX_Const_ShadersManagerName).getResourceByName("world2screenspace.vert");
        //            ShaderDescriptor vertexshaderidentity = (ShaderDescriptor) ResourcesManager.Root().getSubManager(GeoxygeneConstants.GEOX_Const_ShadersManagerName).getResourceByName("identity.vert");
        //            colorProgram.addVertexShader(GLTools.readFileAsString(vertexshaderidentity.getShaderFilePath()), vertexshaderidentity.getName());
        //
        //            ShaderDescriptor polycolor = (ShaderDescriptor)  ResourcesManager.Root().getSubManager(GeoxygeneConstants.GEOX_Const_ShadersManagerName).getResourceByName("polygon.color.frag");
        //            colorProgram.addVertexShader(GLTools.readFileAsString(vertexshader.getShaderFilePath()), vertexshader.getName());
        //            colorProgram.addFragmentShader(GLTools.readFileAsString(polycolor.getShaderFilePath()), polycolor.getName());
        //            colorProgram.addInputLocation(GLSimpleVertex.VertexUVVarName, GLSimpleVertex.vertexUVLocation);
        //            colorProgram.addInputLocation(GLSimpleVertex.VertexPositionVarName, GLSimpleVertex.vertexPostionLocation);
        //            colorProgram.addInputLocation(GLSimpleVertex.VertexColorVarName, GLSimpleVertex.vertexColorLocation);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_VarName_M00ModelToViewMatrix, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_VarName_M02ModelToViewMatrix, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_VarName_M11ModelToViewMatrix, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_VarName_M12ModelToViewMatrix, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_VarName_ScreenWidth, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_VarName_ScreenHeight, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_VarName_FboWidth, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_VarName_FboHeight, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_Const_GlobalOpacityVarName, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_Const_ObjectOpacityVarName, GLUniformType.GL_FLOAT);
        //            colorProgram.addUniform(GeoxygeneConstants.GL_Const_ColorTexture1Name, GLUniformType.GL_SAMPLER2D);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

}

From source file:fr.ign.cogit.geoxygene.util.gl.GLProgram.java

License:Open Source License

public synchronized int getProgramId() throws GLException {
    if (this.programId < 0) {
        int newProgramId = glCreateProgram();
        if (newProgramId <= 0) {
            throw new GLException("Unable to create GL program " + this.getName() + " using "
                    + this.shaders.size() + " shaders");
        }/*  ww  w.  j  av a  2s. c  o  m*/
        // Set up the shaders used by the program.
        // If the vertex and fragment shaders setup successfully,
        // attach them to the shader program, link the shader program
        // into the GL context, and validate
        for (GLShader shader : this.shaders) {
            int shaderId = shader.getId();
            glAttachShader(newProgramId, shaderId);
        }
        glLinkProgram(newProgramId);
        if (glGetProgrami(newProgramId, GL_LINK_STATUS) == GL_FALSE) {
            System.out.println("GL20.GL_VERTEX_SHADER =" + GL20.GL_VERTEX_SHADER);
            System.out.println("GL20.GL_FRAGMENT_SHADER =" + GL20.GL_FRAGMENT_SHADER);
            logger.error("Link error in program " + this.getName());
            for (GLShader shader : this.shaders) {
                logger.error("- shader " + shader.getName() + " : id = " + shader.getId() + " content = '"
                        + shader.getSource() + "'");
            }
            throw new GLException("GL program '" + this.getName() + "' link error: "
                    + GLTools.getProgramLogInfo(newProgramId));
        }
        glValidateProgram(newProgramId);
        if (glGetProgrami(newProgramId, GL_VALIDATE_STATUS) == GL_FALSE) {
            throw new GLException("GL program '" + this.getName() + "' validation error: "
                    + GLTools.getProgramLogInfo(newProgramId));
        } else {
            logger.info("\tProgram '" + this.getName() + "' created and validated. Shader count="
                    + this.shaders.size());
        }
        this.programId = newProgramId;
    }
    return this.programId;
}