Example usage for org.lwjgl.opengl GL20 glCreateShader

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

Introduction

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

Prototype

@NativeType("GLuint")
public static int glCreateShader(@NativeType("GLenum") int type) 

Source Link

Document

Creates a shader object.

Usage

From source file:com.github.kajdreef.mazerunnermvn.MazeRunner.ShaderProgram.java

public int compileShader(int shaderType, String shaderName) {
    // Initialize the vertex Shader
    int shaderId = GL20.glCreateShader(shaderType);
    GL20.glShaderSource(shaderId, loadShader(defaultShaderLocation + shaderName));
    GL20.glCompileShader(shaderId);/*  w  ww  . j  a  v  a2  s .  c o m*/

    // Check if the vertex shader compiled
    if (GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        log.logError("Failed to compile " + shaderName + " shader");
        System.exit(-1);
    }

    return shaderId;
}

From source file:com.github.ryancwilliams.WJ3dPL.graphics.GLUtils.ShaderProgram.java

License:Apache License

/**
 * Compiles a shader from the provided source and returns its OpenGL handle.
 * @param type the shader type to use when compiling.
 * @param source the source to compile./*from ww w .ja  v a2 s  .c o  m*/
 * @return the OpenGL handle for this shader.
 * @throws LWJGLException if compilation was unsuccessful
 */
public static int compileShader(int type, String source) throws LWJGLException {
    //Create the shader ponter varable
    int shader;
    //Create the shader
    shader = GL20.glCreateShader(type);

    //load the source
    GL20.glShaderSource(shader, source);
    //compile the source
    GL20.glCompileShader(shader);

    //Get if the compile was good
    boolean compile = GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == GL11.GL_TRUE;

    //Get the log
    String infoLog = GL20.glGetShaderInfoLog(shader, GL20.glGetShaderi(shader, GL20.GL_INFO_LOG_LENGTH));

    //Log the log if a log is present
    if (infoLog != null && infoLog.trim().length() != 0) {
        Logger.getLogger(ShaderProgram.class.getName()).log(Level.FINEST, infoLog);
    }

    //Check if the compiling was unsuccessful
    if (compile == false) {
        //throw a exception if unsuccessful
        throw new LWJGLException(
                "Failure in compiling " + ShaderProgram.typeToString(type) + ". Error log:\n" + infoLog);
    }

    //Return the OpenGL pointer for the shader
    return shader;
}

From source file:com.google.gapid.glviewer.gl.Shader.java

License:Apache License

private static int createShader(int type, String source) {
    int shader = GL20.glCreateShader(type);
    GL20.glShaderSource(shader, source);
    GL20.glCompileShader(shader);/*from   w w  w  .  j a  va2s . co  m*/
    if (GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        LOG.log(WARNING,
                "Failed to compile shader:\n" + GL20.glGetShaderInfoLog(shader) + "\n\nSource:\n" + source);
        GL20.glDeleteShader(shader);
        return -1;
    }
    return shader;
}

From source file:com.grillecube.client.opengl.GLShader.java

public static int loadShader(String filepath, int type, String preprocessor) {
    Logger.get().log(Logger.Level.FINE, "Loading shader: " + filepath);

    try {/*from w  w w  .j  a  va2 s  .  com*/
        String source = readFile(filepath) + preprocessor;
        int shader_id = GL20.glCreateShader(type);
        GL20.glShaderSource(shader_id, source);
        GL20.glCompileShader(shader_id);
        if (GL20.glGetShaderi(shader_id, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            System.out.println(GL20.glGetShaderInfoLog(shader_id, 512));
            System.err.println("Couldnt compile shader: " + filepath);
            return (-1);
        }
        return (shader_id);
    } catch (IOException e) {
        System.out.println("couldnt read file: " + filepath);
        e.printStackTrace();
        return (-1);
    }
}

From source file:com.grillecube.engine.opengl.object.GLShader.java

public static int loadShader(String filepath, int type) {
    Logger.get().log(Logger.Level.FINE, "Loading shader: " + filepath);

    try {//from ww w.  ja va 2  s . c  o m
        String source = readFile(filepath);
        int shader_id = GL20.glCreateShader(type);
        GL20.glShaderSource(shader_id, source);
        GL20.glCompileShader(shader_id);
        if (GL20.glGetShaderi(shader_id, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            System.out.println(GL20.glGetShaderInfoLog(shader_id, 512));
            System.err.println("Couldnt compile shader: " + filepath);
            return (-1);
        }
        return (shader_id);
    } catch (IOException e) {
        System.out.println("couldnt read file: " + filepath);
        e.printStackTrace();
        return (-1);
    }
}

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

License:Open Source License

private int compileShader(int type, String source) {
    int shader = GL20.glCreateShader(type);

    if (shader == 0) {
        throw new RuntimeException();
    }/*w w w  .j  a  va  2s  .co m*/

    GL20.glShaderSource(shader, source);
    GL20.glCompileShader(shader);

    int comp = GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS);
    int len = GL20.glGetShaderi(shader, GL20.GL_INFO_LOG_LENGTH);

    if (comp == GL11.GL_FALSE) {
        throw new RuntimeException(GL20.glGetShaderInfoLog(shader, len));
    }

    return shader;
}

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

License:Open Source License

public static int loadShader(String source, int type) {
    Util.checkErr();//from ww w . j a va  2 s . co m
    int i = GL20.glCreateShader(type);
    Util.checkErr();
    GL20.glShaderSource(i, source);
    Util.checkErr();
    GL20.glCompileShader(i);
    Util.checkErr();
    if (GL20.glGetShaderi(i, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        new DebugExceptionHandler(new Exception(), annotate(source), GL20.glGetShaderInfoLog(i, 2000));
    }
    Util.checkErr();
    return i;
}

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

License:Apache License

private int loadShader(String file, int type) {
    System.out.println("Loading shader <" + file + ">");
    StringBuilder source = new StringBuilder();
    BufferedReader reader = null;
    try {/*from   w ww.  j av  a2  s .c o m*/
        reader = new BufferedReader(new FileReader(file));
        String line = null;
        while ((line = reader.readLine()) != null)
            source.append(line).append("\n");
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Error: Could not read shader file: " + file);
        System.exit(1);
    } finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

    int shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, source);
    GL20.glCompileShader(shaderID);
    if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.err.println("Error: Could not comple shader");
        System.err.println(GL20.glGetShaderInfoLog(shaderID, 500));
        System.exit(1);
    }

    return shaderID;
}

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

License:Open Source License

@SuppressWarnings("deprecation")
public void addProgram(final String text, final int type) {
    final int shader = GL20.glCreateShader(type);
    if (shader == 0) {
        System.out.println("Shader is 0.");
        System.exit(0);/*  w  w w.j a v a 2s .c o  m*/
    }
    GL20.glShaderSource(shader, text);
    GL20.glCompileShader(shader);
    if (GL20.glGetShader(shader, GL20.GL_COMPILE_STATUS) == 0) {
        System.out.println(GL20.glGetShaderInfoLog(shader, 1024));
        System.exit(1);
    }
    GL20.glAttachShader(shader, this.getProgram());
}

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

Shader(int type) {
    DGL.checkState();//from ww  w .  j ava2s  .  co  m
    if (!DGL.getCapabilities().OpenGL20)
        throw new UnsupportedOperationException("Shaders unsupported in OpenGL < 2.0");
    id = GL20.glCreateShader(type);
    this.type = type;
    state = State.NEW;
}