Example usage for org.lwjgl.opengl GL20 glShaderSource

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

Introduction

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

Prototype

public static void glShaderSource(@NativeType("GLuint") int shader,
        @NativeType("GLchar const **") CharSequence string) 

Source Link

Document

Sets the source code in shader to the source code in the array of strings specified by strings .

Usage

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  a  v 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.wicpar.sinkingsimulatorclassic.graphics.Shader.java

License:Open Source License

public Shader compile() {
    if (ID == null) {
        delete();//from www . jav  a2 s.c o  m
        ID = GL20.glCreateShader(type);
    }
    GL20.glShaderSource(ID, source);
    GL20.glCompileShader(ID);
    if (GL20.glGetShaderi(ID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        logger.error("failed to compile shader: \n" + GL20.glGetShaderInfoLog(ID));
    }
    return this;
}

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;//from w w w.  ja  va  2s . c  om
    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  ww  .j  a va2s  .c  om*/
    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 int compileShader(String source, int shaderType) {
    int vertexShaderId = GL20.glCreateShader(shaderType);
    GL20.glShaderSource(vertexShaderId, source);
    GL20.glCompileShader(vertexShaderId);

    validateCompilation(vertexShaderId);
    return vertexShaderId;
}

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

License:Open Source License

private int compileShader(String source, int shaderType) {
    int vertexShaderId = GL20.glCreateShader(shaderType);
    GL20.glShaderSource(vertexShaderId, source);
    GL20.glCompileShader(vertexShaderId);

    validateCompilation(vertexShaderId);
    return vertexShaderId;
}

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

License:Open Source License

private static int loadShader(final InputStream inputStream, final int type) {
    final StringBuilder builder = new StringBuilder();

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
        String line;/*  w  w  w.  j  av  a 2s  .  co  m*/
        while ((line = reader.readLine()) != null) {
            builder.append(line).append("\n");
        }
        reader.close();
    } catch (final IOException e) {
        e.printStackTrace();
        System.exit(2);
    }

    final int shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, builder);
    GL20.glCompileShader(shaderID);

    Program.checkCompilation(shaderID);

    return shaderID;
}

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

private static int loadShader(String filename, int type) {
    StringBuilder shaderSource = new StringBuilder();
    try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
        String line;//from  w  w w  .  ja v  a2 s . co m
        while ((line = reader.readLine()) != null) {
            shaderSource.append(line).append("\n");
        }
    } catch (IOException e) {
        throw new IllegalStateException("Shader file i/o error", e);
    }

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

    return shaderID;
}

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

License:Apache License

public static void glShaderSource(int shader, String string) {
    GL20.glShaderSource(shader, string);
}

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

License:Open Source License

@Override
public boolean compilerShader(int shader, String source) {
    GL20.glShaderSource(shader, source);
    GL20.glCompileShader(shader);//from   w w  w .j  a  va 2  s.  c o m
    return GL20.glGetShader(shader, GL20.GL_COMPILE_STATUS) == GL11.GL_TRUE;
}