List of usage examples for org.lwjgl.opengl GL20 glCompileShader
public static void glCompileShader(@NativeType("GLuint") int shader)
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); // 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);/* w w w .j av a 2s . c o m*/ } 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./* w w w .j a v a 2s. 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); if (GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { LOG.log(WARNING,//from w w w.j ava 2 s .co m "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 ww w. j a va 2s .c om 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. j a v a 2 s . co 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(); }//from w w w. j a v 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 static int loadShader(String source, int type) { Util.checkErr();// w ww . jav a 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 www . ja 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; }
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 ww. j a v a 2 s . c om } 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. * //from w w w . j av a2 s. c om * @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; }