Example usage for org.lwjgl.opengl GL20 GL_VERTEX_SHADER

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

Introduction

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

Prototype

int GL_VERTEX_SHADER

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

Click Source Link

Document

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

Usage

From source file:com.kauridev.lunarfever.graphics.ShaderProgram.java

License:Open Source License

public ShaderProgram(String vertexShaderSource, String fragShaderSource,
        List<VertexAttribute> attribLocations) {
    if (vertexShaderSource == null || fragShaderSource == null) {
        throw new IllegalArgumentException("shader source must be non-null");
    }//  w  w w  .j a va 2s. c  om

    if (!isSupported()) {
        throw new RuntimeException("no shader support found; shaders require OpenGL 2.0");
    }

    program = createProgram();
    vert = compileShader(GL20.GL_VERTEX_SHADER, vertexShaderSource);
    frag = compileShader(GL20.GL_FRAGMENT_SHADER, fragShaderSource);

    linkProgram(attribLocations);
}

From source file:com.opengrave.og.resources.ShaderProgram.java

License:Open Source License

public void compile() {
    Util.checkErr();// w  ww  .  j a  v a 2  s .  c o m

    PID = GL20.glCreateProgram();
    Util.checkErr();

    vert = loadShader(sfv.getSource(), GL20.GL_VERTEX_SHADER);
    Util.checkErr();

    frag = loadShader(sff.getSource(), GL20.GL_FRAGMENT_SHADER);
    Util.checkErr();

    GL20.glAttachShader(PID, vert);
    Util.checkErr();

    GL20.glAttachShader(PID, frag);
    Util.checkErr();

    GL20.glLinkProgram(PID);
    Util.checkErr();

    System.out.println(GL20.glGetProgramInfoLog(PID, 2000));
    Util.checkErr();

    GL20.glValidateProgram(PID);
    Util.checkErr();

    // System.out.println("Compiled " + label + " as number " + PID);
    if (GL20.glGetProgrami(PID, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
        new DebugExceptionHandler(new Exception(), label, GL20.glGetShaderInfoLog(PID, 2000),
                GL20.glGetProgramInfoLog(PID, 2000));
        // System.out.println("Failed to link " + label);
        // System.out.println(sfv.getSource());
        // System.out.println(sff.getSource());

        // Util.checkErr();

        // printShaderLogs();
    }
    Util.checkErr();

    GL20.glDetachShader(PID, vert);
    Util.checkErr();

    GL20.glDetachShader(PID, frag);
    GL20.glDeleteShader(vert);
    Util.checkErr();

    GL20.glDeleteShader(frag);
    Util.checkErr();
}

From source file:com.redthirddivision.quad.rendering.shaders.Shader.java

License:Apache License

private int loadVertex(String file) {
    return loadShader("source/com/redthirddivision/quad/rendering/shaders/" + file + "_vert.glsl",
            GL20.GL_VERTEX_SHADER);
}

From source file:com.runescape.client.revised.client.lwjgl.Shader.java

License:Open Source License

public void addVertexShader(final String text) {
    this.addProgram(text, GL20.GL_VERTEX_SHADER);
}

From source file:com.samrj.devil.gl.DGL.java

License:Open Source License

/**
 * Generates, loads, compiles, links, and validates a new shader program as
 * well as an underlying vertex and fragment shader. The shader sources are
 * assumed to be in the given path, with the same name, ending in .vert and
 * .frag, respectively./*from w w w .ja  va2s . co  m*/
 * 
 * @param path The directory and name to load sources from.
 * @return A new, complete shader program.
 * @throws IOException 
 */
public static ShaderProgram loadProgram(String path) throws IOException {
    Shader vertShader = loadShader(path + ".vert", GL20.GL_VERTEX_SHADER);
    Shader fragShader = loadShader(path + ".frag", GL20.GL_FRAGMENT_SHADER);
    ShaderProgram program = loadProgram(vertShader, fragShader);
    delete(vertShader, fragShader);
    return program;
}

From source file:com.samrj.devil.graphics.EZDraw.java

/**
 * Initializes EZDraw, preparing it to draw primitives.
 * /*  ww  w .j  a va  2 s . co m*/
 * @param maxVertices The maximum number of vertices that can be drawn by a
 *        single draw command. Determines the amount of memory to be
 *        allocated for the vertex buffer.
 */
public static void init(int maxVertices) {
    if (initialized)
        return;
    if (maxVertices <= 0)
        throw new IllegalArgumentException();

    try {
        Shader vert = DGL.genShader(GL20.GL_VERTEX_SHADER);
        vert.source(IOUtil.stringStream(VERT_SOURCE));
        Shader frag = DGL.genShader(GL20.GL_FRAGMENT_SHADER);
        frag.source(IOUtil.stringStream(FRAG_SOURCE));
        shader = DGL.loadProgram(vert, frag);
        DGL.delete(vert, frag);

        projMat = Mat4.identity();
        stack = new MatStack();
    } catch (IOException e) {
        throw new RuntimeException(e); //Should never reasonably fail.
    }

    stream = DGL.genVertexStream(maxVertices, -1);
    pos = stream.vec3("in_pos");
    color = stream.vec4("in_color");
    color.set(1.0f);
    stream.begin();

    drawMode = -1;
    initialized = true;
}

From source file:com.timvisee.voxeltex.module.shader.raw.RawShader.java

License:Open Source License

@Override
public int compile() {
    // Show a status message
    System.out.print("Compiling shader... ");

    // Create a new OpenGL shader program
    int program = GL20.glCreateProgram();

    // Shader IDs
    int vertexId = 0;
    int fragmentId = 0;

    // Compile the vertex shader if available
    if (hasVertexShader()) {
        // Create the vertex shader
        vertexId = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);

        // Attach the vertex shader source and compile it
        GL20.glShaderSource(vertexId, vertexSource);
        GL20.glCompileShader(vertexId);/*from   w  w  w.  ja  va 2  s.  c o m*/

        // Check for compiling errors
        if (GL20.glGetShaderi(vertexId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            // Show an error message
            System.out.println("FAIL\nFailed to compile the vertex shader");
            System.out.println(GL20.glGetShaderInfoLog(vertexId));

            // Delete the shader before returning
            GL20.glDeleteShader(vertexId);
            throw new RuntimeException("Failed to compile the vertex shader");
        }
    }

    // Compile the fragment shader if available
    if (hasFragmentShader()) {
        // Create the fragment shader
        fragmentId = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);

        // Attach the fragment shader source and compile it
        GL20.glShaderSource(fragmentId, fragmentSource);
        GL20.glCompileShader(fragmentId);

        // Check for compiling errors
        if (GL20.glGetShaderi(fragmentId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            // Show an error message
            System.out.println("FAIL\nFailed to compile the fragment shader");
            System.out.println(GL20.glGetShaderInfoLog(fragmentId));

            // Delete the shader before returning
            GL20.glDeleteShader(fragmentId);
            throw new RuntimeException("Failed to compile the vertex shader");
        }
    }

    // Attach all compiled shaders
    if (hasVertexShader())
        GL20.glAttachShader(program, vertexId);
    if (hasFragmentShader())
        GL20.glAttachShader(program, fragmentId);

    // Link the shader program to OpenGL and link it
    GL20.glLinkProgram(program);
    GL20.glValidateProgram(program);

    // Shaders have been attached to the program, delete their compiled sources to save memory
    if (hasVertexShader())
        GL20.glDeleteShader(vertexId);
    if (hasFragmentShader())
        GL20.glDeleteShader(fragmentId);

    // Show a status message
    System.out.println("OK");

    // Return the created OpenGL shader program
    return program;
}

From source file:com.voxelplugineering.voxelsniper.render.RenderMain.java

License:Open Source License

private void setupShaders() {
    // Load the vertex shader
    int vsId = GLSLUtilities.loadShader("assets/shaders/vertex.glsl", GL20.GL_VERTEX_SHADER);
    // Load the fragment shader
    int fsId = GLSLUtilities.loadShader("assets/shaders/fragment.glsl", GL20.GL_FRAGMENT_SHADER);

    // Create a new shader program that links both shaders
    pId = GL20.glCreateProgram();//w  ww  . jav  a  2s .c om
    GL20.glAttachShader(pId, vsId);
    GL20.glAttachShader(pId, fsId);

    GL20.glBindAttribLocation(pId, 0, "in_Position");
    GL20.glBindAttribLocation(pId, 1, "in_Color");
    GL20.glBindAttribLocation(pId, 2, "in_TextureCoord");

    GL20.glLinkProgram(pId);
    GL20.glValidateProgram(pId);

    // Get matrices uniform locations
    projectionMatrixLocation = GL20.glGetUniformLocation(pId, "projectionMatrix");
    viewMatrixLocation = GL20.glGetUniformLocation(pId, "viewMatrix");
    modelMatrixLocation = GL20.glGetUniformLocation(pId, "modelMatrix");

    OpenGLUtilities.checkGLError("setupShaders");
}

From source file:com.xrbpowered.gl.res.shaders.Shader.java

License:Open Source License

public Shader(VertexInfo info, String pathVS, String pathFS) {
    //      System.out.println("Compile: "+pathVS+", "+pathFS);
    this.info = info;
    int vsId = loadShader(pathVS, GL20.GL_VERTEX_SHADER);
    int fsId = loadShader(pathFS, GL20.GL_FRAGMENT_SHADER);

    pId = GL20.glCreateProgram();//  w w  w . ja v a 2s.  c  om
    if (vsId > 0)
        GL20.glAttachShader(pId, vsId);
    if (fsId > 0)
        GL20.glAttachShader(pId, fsId);

    bindAttribLocations();

    //      System.out.println("Link: "+pathVS+", "+pathFS);
    GL20.glLinkProgram(pId);
    if (GL20.glGetProgrami(pId, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
        System.err.println("Could not link program " + pathVS + ", " + pathFS);
        System.err.println(GL20.glGetProgramInfoLog(pId, 8000));
        System.exit(-1);
    }
    GL20.glValidateProgram(pId);

    storeUniformLocations();
    Client.checkError();
    //      System.out.println("Done: "+pathVS+", "+pathFS+"\n");
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public int compileShader(String source, boolean isVertex) {

    int type;//from  w  w  w  .j  a  va 2s. c o  m
    if (isVertex) {
        type = GL20.GL_VERTEX_SHADER;
    } else {
        type = GL20.GL_FRAGMENT_SHADER;
    }

    int id = GL20.glCreateShader(type);
    GL20.glShaderSource(id, source);
    GL20.glCompileShader(id);

    boolean isSuccess = GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS) != GL11.GL_FALSE;
    if (!isSuccess) {

        // get debug info
        StringBuilder buf = new StringBuilder();
        buf.append("Shader did not compile\n");

        // show the compiler log
        buf.append("\nCOMPILER LOG:\n");
        buf.append(GL20.glGetShaderInfoLog(id, 4096));

        // show the source with correct line numbering
        buf.append("\nSOURCE:\n");
        String[] lines = source.split("\\n");
        for (int i = 0; i < lines.length; i++) {
            buf.append(String.format("%4d: ", i + 1));
            buf.append(lines[i]);
            buf.append("\n");
        }

        throw new RuntimeException(buf.toString());
    }

    return id;
}