List of usage examples for org.lwjgl.opengl GL20 glGetShaderInfoLog
@NativeType("void") public static String glGetShaderInfoLog(@NativeType("GLuint") int shader, @NativeType("GLsizei") int maxLength)
From source file:br.com.perin.shaders.ShaderProgram.java
private static int loadShader(String file, int type) { StringBuilder shaderSource = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line;//from w w w . j a va 2s. c o m while ((line = reader.readLine()) != null) { shaderSource.append(line).append("//\n"); } } catch (IOException e) { e.printStackTrace(); System.exit(-1); } int shaderID = GL20.glCreateShader(type); GL20.glShaderSource(shaderID, shaderSource); GL20.glCompileShader(shaderID); if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { System.out.println(GL20.glGetShaderInfoLog(shaderID, 500)); System.err.println("Could not compile shader!"); System.exit(-1); } return shaderID; }
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Shader.java
License:MIT License
@Override public void compile() { checkCreated();/*from w ww . j a v a 2 s.c o m*/ // Compile the shader GL20.glCompileShader(id); // Get the shader compile status property, check it's false and fail if that's the case if (GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { throw new IllegalStateException( "OPEN GL ERROR: Could not compile shader\n" + GL20.glGetShaderInfoLog(id, 1000)); } // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.geekyaubergine.geekyjgameutil.shader.ShaderProgram.java
License:Open Source License
/** * Loads shader program from file and returns the shader ID * @param file File to read/*from w ww. j a va 2 s . c om*/ * @param type Type of shader * @return Shader ID * @throws IOException */ private int loadShaderFile(File file, int type) throws IOException { List<String> lines = FileUtil.readLinesFromFile(file, false, true); StringBuilder shaderSource = new StringBuilder(); for (String line : lines) { shaderSource.append(line).append("\n"); } int shaderID = GL20.glCreateShader(type); GL20.glShaderSource(shaderID, shaderSource); GL20.glCompileShader(shaderID); if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { Log.error("Could not complile shader"); Log.error(GL20.glGetShaderInfoLog(shaderID, 500)); } 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. j av a2 s . c om * @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.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 {/*w w w. jav a2 s . c o m*/ 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 www . jav a2 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 av a2 s .c o 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 void compile() { Util.checkErr();//from w w w. j av a2 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.opengrave.og.resources.ShaderProgram.java
License:Open Source License
public static int loadShader(String source, int type) { Util.checkErr();/*from w w w. j a v a2 s. c o 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 a v a 2 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; }