List of usage examples for org.lwjgl.opengl GL20 glShaderSource
public static void glShaderSource(@NativeType("GLuint") int shader, @NativeType("GLchar const **") CharSequence string)
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 va2s.c om // 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 w w w .j av a2s . co 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 ww .j a v a 2s . c om*/ 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 . ja va2 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 ww w. j a va 2 s .com 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 ava 2 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();//from www. j a v a 2 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 {/* www . ja v a 2 s . c om*/ 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);//from w ww . j a v a 2s .com } 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.timvisee.voxeltex.module.shader.raw.RawShader.java
License:Open Source License
@Override public int compile() { // Show a status message System.out.print("Compiling shader... "); // Create a new OpenGL shader program int program = GL20.glCreateProgram(); // Shader IDs int vertexId = 0; int fragmentId = 0; // Compile the vertex shader if available if (hasVertexShader()) { // Create the vertex shader vertexId = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); // Attach the vertex shader source and compile it GL20.glShaderSource(vertexId, vertexSource); GL20.glCompileShader(vertexId);/* ww w. ja v a2 s . c o m*/ // Check for compiling errors if (GL20.glGetShaderi(vertexId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { // Show an error message System.out.println("FAIL\nFailed to compile the vertex shader"); System.out.println(GL20.glGetShaderInfoLog(vertexId)); // Delete the shader before returning GL20.glDeleteShader(vertexId); throw new RuntimeException("Failed to compile the vertex shader"); } } // Compile the fragment shader if available if (hasFragmentShader()) { // Create the fragment shader fragmentId = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); // Attach the fragment shader source and compile it GL20.glShaderSource(fragmentId, fragmentSource); GL20.glCompileShader(fragmentId); // Check for compiling errors if (GL20.glGetShaderi(fragmentId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { // Show an error message System.out.println("FAIL\nFailed to compile the fragment shader"); System.out.println(GL20.glGetShaderInfoLog(fragmentId)); // Delete the shader before returning GL20.glDeleteShader(fragmentId); throw new RuntimeException("Failed to compile the vertex shader"); } } // Attach all compiled shaders if (hasVertexShader()) GL20.glAttachShader(program, vertexId); if (hasFragmentShader()) GL20.glAttachShader(program, fragmentId); // Link the shader program to OpenGL and link it GL20.glLinkProgram(program); GL20.glValidateProgram(program); // Shaders have been attached to the program, delete their compiled sources to save memory if (hasVertexShader()) GL20.glDeleteShader(vertexId); if (hasFragmentShader()) GL20.glDeleteShader(fragmentId); // Show a status message System.out.println("OK"); // Return the created OpenGL shader program return program; }