Java Code Examples for org.lwjgl.opengl.GL11#GL_FALSE
The following examples show how to use
org.lwjgl.opengl.GL11#GL_FALSE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShaderProgram.java From LowPolyWater with The Unlicense | 6 votes |
private int loadShader(MyFile file, int type) { StringBuilder shaderSource = new StringBuilder(); try { BufferedReader reader = file.getReader(); String line; while ((line = reader.readLine()) != null) { shaderSource.append(line).append("//\n"); } reader.close(); } catch (Exception e) { System.err.println("Could not read file."); 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 "+ file); System.exit(-1); } return shaderID; }
Example 2
Source File: ShaderProgram.java From OpenGL-Animation with The Unlicense | 6 votes |
private int loadShader(MyFile file, int type) { StringBuilder shaderSource = new StringBuilder(); try { BufferedReader reader = file.getReader(); String line; while ((line = reader.readLine()) != null) { shaderSource.append(line).append("//\n"); } reader.close(); } catch (Exception e) { System.err.println("Could not read file."); 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 "+ file); System.exit(-1); } return shaderID; }
Example 3
Source File: ShaderProgram.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
/** * Binds this shader for use, Lazily allocates, links * and compiles all {@link ShaderObject}s. */ public void use() { if (bound) { throw new IllegalStateException("Already bound."); } if (programId == -1 || shaders.stream().anyMatch(ShaderObject::isDirty)) { shaders.forEach(ShaderObject::alloc); if (programId == -1) { programId = GL20.glCreateProgram(); if (programId == 0) { throw new IllegalStateException("Allocation of ShaderProgram has failed."); } shaders.forEach(shader -> GL20.glAttachShader(programId, shader.getShaderID())); } GL20.glLinkProgram(programId); if (GL20.glGetProgrami(programId, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { throw new RuntimeException("ShaderProgram linkage failure. \n" + GL20.glGetProgramInfoLog(programId)); } shaders.forEach(shader -> shader.onLink(programId)); uniformCache.onLink(); } GL20.glUseProgram(programId); bound = true; }
Example 4
Source File: AbstractShaderObject.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void alloc() { if (dirty || shaderId == -1) { if (shaderId == -1) { shaderId = GL20.glCreateShader(type.getGLCode()); if (shaderId == 0) { throw new RuntimeException("Allocation of ShaderObject failed."); } } GL20.glShaderSource(shaderId, getSource()); GL20.glCompileShader(shaderId); if (GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { throw new RuntimeException("ShaderProgram linkage failure. \n" + GL20.glGetShaderInfoLog(shaderId)); } } }
Example 5
Source File: GLShader.java From ldparteditor with MIT License | 6 votes |
public GLShader(final String vertexPath, final String fragmentPath) { final int vertex = createAndCompile(vertexPath, GL20.GL_VERTEX_SHADER); final int fragment = createAndCompile(fragmentPath, GL20.GL_FRAGMENT_SHADER); program = GL20.glCreateProgram(); GL20.glAttachShader(program, fragment); GL20.glAttachShader(program, vertex); GL20.glLinkProgram(program); // FIXME Extract parameter locations // int baseImageLoc = GL20.glGetUniformLocation(program, "colorMap"); //$NON-NLS-1$ if (GL20.glGetProgrami(program, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { NLogger.error(GLShader.class, "Could not link shader: " + GL20.glGetProgramInfoLog(program, 1024)); //$NON-NLS-1$; } GL20.glDetachShader(program, fragment); GL20.glDetachShader(program, vertex); GL20.glDeleteShader(fragment); GL20.glDeleteShader(vertex); }
Example 6
Source File: GLShader.java From ldparteditor with MIT License | 6 votes |
private int createAndCompile(final String path, final int type) { final StringBuilder shaderSource = new StringBuilder(); try (BufferedReader shaderReader = new BufferedReader(new InputStreamReader(GLShader.class.getResourceAsStream(path), "UTF-8"))) { //$NON-NLS-1$) { String line; while ((line = shaderReader.readLine()) != null) { shaderSource.append(line).append("\n"); //$NON-NLS-1$ } } catch (IOException io) { NLogger.error(GLShader.class, io); return -1; } final int shaderID = GL20.glCreateShader(type); GL20.glShaderSource(shaderID, shaderSource); GL20.glCompileShader(shaderID); if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { NLogger.error(GLShader.class, "Could not compile shader " + path + GL20.glGetProgramInfoLog(program, 1024)); //$NON-NLS-1$; NLogger.error(GLShader.class, "msg: " + path + GL20.glGetShaderInfoLog(shaderID)); //$NON-NLS-1$; return -1; } return shaderID; }
Example 7
Source File: ShaderProgramBuilder.java From OpenModsLib with MIT License | 6 votes |
private static int createShader(ResourceLocation source, int type) { int shader = 0; try { shader = ShaderHelper.methods().glCreateShader(type); if (shader == 0) throw new OpenGLException("Error creating shader object"); ShaderHelper.methods().glShaderSource(shader, readShaderSource(source)); ShaderHelper.methods().glCompileShader(shader); if (ShaderHelper.methods().glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) throw new OpenGLException("Shader compile error: " + ShaderHelper.methods().getShaderLogInfo(shader)); return shader; } catch (Throwable t) { ShaderHelper.methods().glDeleteShader(shader); throw t; } }
Example 8
Source File: ShaderUtil.java From Cyberware with MIT License | 5 votes |
private static int createShader(String filename, int shaderType) { int shader = 0; try { shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType); if(shader == 0) { return 0; } ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename)); ARBShaderObjects.glCompileShaderARB(shader); if (ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE) throw new RuntimeException("Error creating shader: " + getLogInfo(shader)); return shader; } catch(Exception e) { ARBShaderObjects.glDeleteObjectARB(shader); e.printStackTrace(); return -1; } }
Example 9
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 5 votes |
private int loadShader(String filename, int type) { StringBuilder shaderSource = new StringBuilder(); int shaderID = 0; try { 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.glGetShader(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { System.err.println("Could not compile shader."); System.exit(-1); } this.exitOnGLError("loadShader"); return shaderID; }
Example 10
Source File: OpenGLRenderer20.java From ldparteditor with MIT License | 5 votes |
private int loadGlossFragmentShader() { StringBuilder shaderSource = new StringBuilder(); int shaderID = 0; try { BufferedReader reader = new BufferedReader(new InputStreamReader(GLShader.class.getResourceAsStream("gloss.frag"), "UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$ String line; while ((line = reader.readLine()) != null) { shaderSource.append(line).append("\n"); //$NON-NLS-1$ } reader.close(); } catch (IOException e) { NLogger.error(OpenGLRenderer20.class, e); return -1; } shaderID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); GL20.glShaderSource(shaderID, shaderSource); GL20.glCompileShader(shaderID); if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { NLogger.error(OpenGLRenderer20.class, new Exception("Could not compile fragment shader.")); //$NON-NLS-1$; return -1; } return shaderID; }
Example 11
Source File: OpenGLRenderer20.java From ldparteditor with MIT License | 5 votes |
private int loadGlossVertexShader() { StringBuilder shaderSource = new StringBuilder(); int shaderID = 0; try { BufferedReader reader = new BufferedReader(new InputStreamReader(GLShader.class.getResourceAsStream("gloss.vert"), "UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$ String line; while ((line = reader.readLine()) != null) { shaderSource.append(line).append("\n"); //$NON-NLS-1$ } reader.close(); } catch (IOException e) { NLogger.error(OpenGLRenderer20.class, e); return -1; } shaderID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); GL20.glShaderSource(shaderID, shaderSource); GL20.glCompileShader(shaderID); if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { NLogger.error(OpenGLRenderer20.class, new Exception("Could not compile vertex shader.")); //$NON-NLS-1$; return -1; } return shaderID; }
Example 12
Source File: ShaderProgram.java From caliko with MIT License | 5 votes |
/** * Load and compile a shader from GLSL source code provided as a String. * <p> * * If the shader could not be created, or if there was a error compiling the GLSL source code * for the shader then a RuntimeException is thrown. * * @param shaderSource The GLSL source code for the shader. * @param shaderType The type of shader to create, typically GL_VERTEX_SHADER or GL_FRAGMENT_SHADER. * @return The shader id * @see <a href="https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glCreateShader.xml">glCreateShader</a> * @see <a href="https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glShaderSource.xml">glShaderSource</a> * @see <a href="https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glCompileShader.xml">glCompileShader</a> */ private int compileShaderFromString(String shaderSource, int shaderType) { // The shaderId will be non-zero if successfully created int shaderId = glCreateShader(shaderType); // Throw a RuntimeException is there was a problem creating the shader if (shaderId == 0) { throw new RuntimeException( "Shader creation failed: " + glGetProgramInfoLog(mProgramId, 1000) ); } // Attach the GLSL source code to the shader glShaderSource(shaderId, shaderSource); // Compile the shader glCompileShader(shaderId); // Get the shader compilation status int shaderStatus = glGetShaderi(shaderId, GL_COMPILE_STATUS); // If the shader failed to compile then throw a RuntimeException with debug info if (shaderStatus == GL11.GL_FALSE) { throw new RuntimeException("Shader compilation failed: " + glGetShaderInfoLog(shaderId, 1000) ); } return shaderId; }
Example 13
Source File: ShaderProgram.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public void link() { glLinkProgramARB(programID); if(glGetObjectParameteriARB(programID, GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) throw new RuntimeException("Error linking program: "+getInfoLog(programID)); glValidateProgramARB(programID); if(glGetObjectParameteriARB(programID, GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) throw new RuntimeException("Error validating program: "+getInfoLog(programID)); use(); onLink(); restore(); }
Example 14
Source File: GenericShader.java From LWJGUI with MIT License | 4 votes |
protected static int compileShader(String source, boolean isVertex) { int type; if (isVertex) { type = GL20.GL_VERTEX_SHADER; } else { type = GL20.GL_FRAGMENT_SHADER; } // try to massage JavaFX shaders into modern OpenG if (source.startsWith("#ifdef GL_ES\n")) { source = modernizeShader(source, isVertex); } 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; }
Example 15
Source File: ShaderUtil.java From Cyberware with MIT License | 4 votes |
private static int createShader(String vert, String frag) { int fragid = 0; int vertid = 0; if (frag != null) { fragid = createShader(frag, FRAG); } if (vert != null) { vertid = createShader(vert, VERT); } int program = ARBShaderObjects.glCreateProgramObjectARB(); if (program == 0) { return 0; } if (frag != null) { ARBShaderObjects.glAttachObjectARB(program, fragid); } if (vert != null) { ARBShaderObjects.glAttachObjectARB(program, vertid); } ARBShaderObjects.glLinkProgramARB(program); if(ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) { System.out.println("BAD: " + getLogInfo(program)); return 0; } if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) { System.out.println("BAD: " + getLogInfo(program)); return 0; } return program; }