List of usage examples for org.lwjgl.opengl GL20 glCreateProgram
@NativeType("GLuint") public static int glCreateProgram()
From source file:com.github.ryancwilliams.WJ3dPL.graphics.GLUtils.ShaderProgram.java
License:Apache License
/** * Creates a new shader program with the provided vertex and fragment * shader source code.//from www .j a v a 2s. c o m * The provided attributes are linked to this program. * @param vertexShaderSource the source code of the vertex shader. * @param fragmentShaderSource the source code of the fragment shader. * @param attributes The Vertex Attributes to bind to this shader program. * @throws LWJGLException If their is a issue compiling the shaders or * creating or binding the program. */ public ShaderProgram(String vertexShaderSource, String fragmentShaderSource, List<VertexAttribute> attributes) throws LWJGLException { //Check if any of the sourcecode paramaters are null if (fragmentShaderSource == null || fragmentShaderSource == null) { //If any of the sourcecode paramaters were null //throw a exception throw new IllegalArgumentException("Shader source may not be null"); } //Check if shaders are not supported if (!ShaderProgram.isSupported()) { //If shaders are not supported //throw a exception throw new LWJGLException("Shaders are not supported on this device"); } //Compile the shaders int vertexShader = ShaderProgram.compileShader(GL20.GL_VERTEX_SHADER, vertexShaderSource); int fragmentShader = ShaderProgram.compileShader(GL20.GL_FRAGMENT_SHADER, fragmentShaderSource); //Create the program this.program = GL20.glCreateProgram(); //Bind the attrib locations //Check if attributes were provided if (attributes != null) { //For each attribute for (VertexAttribute attribute : attributes) { //Check if the attribute is not null if (attribute != null) { //bind the attribute GL20.glBindAttribLocation(this.program, attribute.index, attribute.name); } } } //Attach the shaders GL20.glAttachShader(this.program, vertexShader); GL20.glAttachShader(this.program, fragmentShader); //Link the program GL20.glLinkProgram(this.program); //Get if the program link was good boolean programLink = GL20.glGetProgrami(this.program, GL20.GL_LINK_STATUS) == GL11.GL_TRUE; //Get the log String infoLog = GL20.glGetProgramInfoLog(this.program, GL20.glGetProgrami(this.program, 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 program link is bad if (programLink == false) { throw new LWJGLException("Failure in linking program. Error log:\n" + infoLog); } //detach and delete the shaders which are no longer needed GL20.glDetachShader(this.program, vertexShader); GL20.glDetachShader(this.program, fragmentShader); GL20.glDeleteShader(vertexShader); GL20.glDeleteShader(fragmentShader); }
From source file:com.google.gapid.glviewer.gl.Shader.java
License:Apache License
Shader(Renderer owner) { super(owner); this.handle = GL20.glCreateProgram(); owner.register(this); }
From source file:com.grillecube.client.opengl.GLProgram.java
public void link() { this.progID = GL20.glCreateProgram(); for (GLShader shader : this.shaders) { GL20.glAttachShader(this.progID, shader.getID()); }/* w w w .ja v a 2 s . co m*/ this.bindAttributes(); GL20.glLinkProgram(this.progID); String message = GL20.glGetProgramInfoLog(this.progID); if (message.length() > 0) { Logger.get().log(Logger.Level.WARNING, "Linking shader message: " + message); } GL20.glValidateProgram(this.progID); this.linkUniforms(); GLH.glhAddObject(this); }
From source file:com.grillecube.engine.opengl.object.GLProgram.java
public void link() { this._programID = GL20.glCreateProgram(); for (GLShader shader : this._shaders) { GL20.glAttachShader(this._programID, shader.getID()); }//w w w . j a v a2 s .c o m this.bindAttributes(); GL20.glLinkProgram(this._programID); String message = GL20.glGetProgramInfoLog(this._programID); if (message.length() > 0) { Logger.get().log(Logger.Level.WARNING, "Linking shader message: " + message); } GL20.glValidateProgram(this._programID); this.linkUniforms(); GLH.glhAddObject(this); }
From source file:com.kauridev.lunarfever.graphics.ShaderProgram.java
License:Open Source License
private int createProgram() { int program = GL20.glCreateProgram(); if (program == 0) { throw new RuntimeException(); }//from ww w .jav a 2 s . c om return program; }
From source file:com.opengrave.og.resources.ShaderProgram.java
License:Open Source License
public void compile() { Util.checkErr();//from w w w . ja v a 2 s .co 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.redthirddivision.quad.rendering.shaders.Shader.java
License:Apache License
public Shader(String file) { this.vertexID = loadVertex(file); this.fragmentID = loadFragment(file); this.programID = GL20.glCreateProgram(); GL20.glAttachShader(programID, vertexID); GL20.glAttachShader(programID, fragmentID); bindAttributes();/*from w w w. j a v a 2s. c o m*/ GL20.glLinkProgram(programID); GL20.glValidateProgram(programID); addUniforms(); }
From source file:com.runescape.client.revised.client.lwjgl.Shader.java
License:Open Source License
public Shader() { this.setProgram(GL20.glCreateProgram()); if (this.getProgram() == 0) { System.out.println("Program is set to 0."); System.exit(0);//from w ww .j a va 2 s . c o m } }
From source file:com.samrj.devil.gl.ShaderProgram.java
License:Open Source License
ShaderProgram() { DGL.checkState();/*w w w . j a v a2s .co m*/ if (!DGL.getCapabilities().OpenGL20) throw new UnsupportedOperationException("Shader programs unsupported in OpenGL < 2.0"); id = GL20.glCreateProgram(); shaders = new IdentitySet<>(); state = State.NEW; }
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);/*from w ww . ja v a 2 s . c om*/ // 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; }