Java Code Examples for org.lwjgl.opengl.GL20#glShaderSource()
The following examples show how to use
org.lwjgl.opengl.GL20#glShaderSource() .
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: 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 4
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 5
Source File: DesktopComputeJobManager.java From graphicsfuzz with Apache License 2.0 | 5 votes |
@Override public void createAndCompileComputeShader(String computeShaderSource) { Gdx.app.log("DesktopComputeJobManager", "Compiling compute shader."); shader = GL20.glCreateShader(GL43.GL_COMPUTE_SHADER); checkError(); GL20.glShaderSource(shader, computeShaderSource); checkError(); GL20.glCompileShader(shader); checkError(); }
Example 6
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 7
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 8
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 9
Source File: LWJGL20DrawContext.java From settlers-remake with MIT License | 5 votes |
private int createShader(String name, int type) throws IOException { int shader = GL20.glCreateShader(type); setObjectLabel(KHRDebug.GL_SHADER, shader, name); BufferedReader is = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/"+name))); StringBuilder source = new StringBuilder(); String line; while((line = is.readLine()) != null) { source.append(line).append("\n"); } GL20.glShaderSource(shader, source); GL20.glCompileShader(shader); String log = GL20.glGetShaderInfoLog(shader); if(debugOutput != null && !log.isEmpty()) System.out.print("info log of " + name + "=====\n" + log + "==== end\n"); if(GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == 0) { GL20.glDeleteShader(shader); throw new Error("Could not compile " + name); } return shader; }
Example 10
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 11
Source File: ShaderHelper.java From OpenModsLib with MIT License | 4 votes |
@Override public void glShaderSource(int shader, String shaderSource) { GL20.glShaderSource(shader, shaderSource); }