Example usage for org.lwjgl.opengl GL20 glGetShaderInfoLog

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

Introduction

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

Prototype

@NativeType("void")
public static String glGetShaderInfoLog(@NativeType("GLuint") int shader,
        @NativeType("GLsizei") int maxLength) 

Source Link

Document

Returns the information log for a shader object.

Usage

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);/*from   w  w  w. j  a  va2  s. co  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

/**
 * Loads shader sources from the given input stream and then compiles this
 * shader. Buffers the source in native memory.
 * //  w ww.  jav  a 2  s  .  c  o m
 * @param in The input stream to load sources from.
 * @return This shader.
 * @throws IOException If an I/O error occurs.
 */
public Shader source(InputStream in) throws IOException {
    if (state != State.NEW)
        throw new IllegalStateException("Shader must be new.");

    //Source to memory
    int sourceLength = in.available();
    Memory sourceBlock = new Memory(sourceLength);
    ByteBuffer sourceBuffer = sourceBlock.buffer;
    for (int i = 0; i < sourceLength; i++)
        sourceBuffer.put((byte) in.read());

    //Pointer to pointer to memory
    long pointer = MemStack.wrapl(sourceBlock.address);

    //Pointer to length of memory
    long length = MemStack.wrapi(sourceLength);

    //Load shader source
    GL20.nglShaderSource(id, 1, pointer, length);

    //Free allocated memory
    MemStack.pop(2);
    sourceBlock.free();

    //Compile
    GL20.glCompileShader(id);

    //Check for errors
    if (GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        int logLength = GL20.glGetShaderi(id, GL20.GL_INFO_LOG_LENGTH);
        String log = GL20.glGetShaderInfoLog(id, logLength);
        throw new ShaderException(path != null ? path + " " + log : log);
    }

    state = State.COMPILED;
    return this;
}

From source file:com.voxelplugineering.voxelsniper.util.GLSLUtilities.java

License:Open Source License

public static int loadShader(String filename, int type) {
    StringBuilder shaderSource = new StringBuilder();
    int shaderID = 0;

    try {/*w w w . j  av  a  2s.  c  o m*/
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        String line;
        while ((line = reader.readLine()) != null) {
            shaderSource.append(line).append("\n");
        }
        reader.close();
    } catch (IOException e) {
        System.err.println("Could not read file.");
        e.printStackTrace();
        System.exit(-1);
    }

    shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, shaderSource);
    GL20.glCompileShader(shaderID);

    if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.err.println("Could not compile shader.");
        System.err.println(GL20.glGetShaderInfoLog(shaderID, 1024));
        System.exit(-1);
    }

    OpenGLUtilities.checkGLError("loadShader");

    return shaderID;
}

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

License:Open Source License

public static int loadShader(String path, int type) {
    if (path == null)
        return 0;
    int shaderId = 0;
    String shaderSource;//w  w w  .  j  a v a2 s . c  o  m
    try {
        shaderSource = AssetManager.defaultAssets.loadString(path);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    shaderId = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderId, shaderSource);
    GL20.glCompileShader(shaderId);

    if (GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.err.println("Could not compile shader " + path);
        System.err.println(GL20.glGetShaderInfoLog(shaderId, 8000));
        System.exit(-1); // FIXME handle this exception!!
    }

    return shaderId;
}

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  .ja  v  a 2  s  . 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;
}

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

License:Open Source License

private static void validateCompilation(int shaderId) {
    int compileStatus = GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS);
    int error = GL11.glGetError();

    if (error != GL11.GL_NO_ERROR) {
        ML.f(String.format("Error getting compilation status: 0x%x", error));
    } else if (compileStatus == GL11.GL_FALSE) {
        int logLength = GL20.glGetShaderi(shaderId, GL20.GL_INFO_LOG_LENGTH);
        String log = GL20.glGetShaderInfoLog(shaderId, logLength);
        ML.f(String.format("Error compiling shader: %s", log));
    }/*www .  ja  va  2  s  .  c o m*/
}

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

License:Open Source License

private void validateCompilation(int shaderId) {
    int compileStatus = GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS);
    int error = GL11.glGetError();

    if (error != GL11.GL_NO_ERROR) {
        ML.f(String.format("Error getting compilation status: 0x%x", error));
    } else if (compileStatus == GL11.GL_FALSE) {
        int logLength = GL20.glGetShaderi(shaderId, GL20.GL_INFO_LOG_LENGTH);
        String log = GL20.glGetShaderInfoLog(shaderId, logLength);
        ML.f(String.format("Error compiling shader: %s", log));
    }/*from ww  w  .j  a v a2 s. c om*/
}

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

License:Open Source License

private static void checkCompilation(final int shaderID) {
    final int error = GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS);
    if (error == GL11.GL_FALSE) {
        throw new OpenGLException(
                GL20.glGetShaderInfoLog(shaderID, GL20.glGetShaderi(shaderID, GL20.GL_INFO_LOG_LENGTH)));
    } else {/*from www. j a v a 2s.  c o  m*/
        System.out.println("Shader Compilation OK");
    }
}

From source file:io.root.gfx.glutils.GL.java

License:Apache License

public static String glGetShaderInfoLog(int shader, int maxLength) {
    return GL20.glGetShaderInfoLog(shader, maxLength);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public String getShaderInfoLog(int shader) {
    int infoLogLength = GL20.glGetShader(shader, GL20.GL_INFO_LOG_LENGTH);
    if (infoLogLength <= 1) {
        return null;
    }/*from   ww  w  . j  a  v a 2  s  . c  o m*/

    String infoLog = GL20.glGetShaderInfoLog(shader, infoLogLength);

    // Remove ending '\0' byte(s)
    while (infoLog.length() > 0 && infoLog.charAt(infoLog.length() - 1) == '\0') {
        infoLog = infoLog.substring(0, infoLog.length() - 1);
    }

    return infoLog;
}