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:opengl.test.object.tree.testobject.leaf.java
private void fragmentShader(String file) { this.fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); GL20.glShaderSource(this.fragmentID, leaf.sourceLoader(file)); GL20.glCompileShader(this.fragmentID); if (GL20.glGetShaderi(this.fragmentID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { throw new RuntimeException("Khong the compile fragmentShader"); }/*w ww .java 2 s . co m*/ GL20.glAttachShader(this.programID, this.fragmentID); }
From source file:opengl.test.object.tree.testobject.traicay.java
private void vertexShader(String file) { this.vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); GL20.glShaderSource(this.vertexID, traicay.sourceLoader(file)); GL20.glCompileShader(this.vertexID); if (GL20.glGetShaderi(this.vertexID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { throw new RuntimeException("Khong the compile vertexShader"); }//from ww w . j a va2 s. c om GL20.glAttachShader(this.programID, this.vertexID); }
From source file:opengl.test.object.tree.testobject.traicay.java
private void fragmentShader(String file) { this.fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); GL20.glShaderSource(this.fragmentID, traicay.sourceLoader(file)); GL20.glCompileShader(this.fragmentID); if (GL20.glGetShaderi(this.fragmentID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { throw new RuntimeException("Khong the compile fragmentShader"); }// w ww. j a v a 2 s . c o m GL20.glAttachShader(this.programID, this.fragmentID); }
From source file:opengl.test.object.tree.testobject.trunk.java
private void vertexShader(String file) { this.vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); GL20.glShaderSource(this.vertexID, trunk.sourceLoader(file)); GL20.glCompileShader(this.vertexID); if (GL20.glGetShaderi(this.vertexID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { throw new RuntimeException("Khong the compile vertexShader"); }/*w w w.j a va2 s. c om*/ GL20.glAttachShader(this.programID, this.vertexID); }
From source file:opengl.test.object.tree.testobject.trunk.java
private void fragmentShader(String file) { this.fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); GL20.glShaderSource(this.fragmentID, trunk.sourceLoader(file)); GL20.glCompileShader(this.fragmentID); if (GL20.glGetShaderi(this.fragmentID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { throw new RuntimeException("Khong the compile fragmentShader"); }//from w ww .j ava2s .co m GL20.glAttachShader(this.programID, this.fragmentID); }
From source file:org.bonsaimind.badgersvoyage.tools.planetstudio.Studio.java
License:Open Source License
public Studio(String title, int width, int height) throws LWJGLException { PixelFormat pixelFormat = new PixelFormat(); ContextAttribs contextAttribs = new ContextAttribs(3, 2); contextAttribs.withForwardCompatible(true); contextAttribs.withProfileCore(true); Display.setDisplayMode(new DisplayMode(width, height)); Display.setTitle(title);/*ww w. j a va2s .com*/ Display.create(pixelFormat, contextAttribs); ErrorChecker.exitOnOpenGlError("Display creation."); programId = GL20.glCreateProgram(); ErrorChecker.exitOnOpenGlError("Program creation."); int shaderId = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); // GL20.glShaderSource(shaderId, "void main {\n" // + " gl_Normal = gl_NormalMatrix * gl_Normal; //Note that you can perform operations on matrices and vectors as if they were\n" // + " //primitive types. This is useful for simple, readable code like this.\n" // + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; //The order in which you times matrices and vertices is IMPORTANT.\n" // + " gl_FrontColor = gl_Color; //These lines just pass on the colour value to the fragment shader.\n" // + " gl_BackColor = gl_Color;\n" // + "}"); GL20.glShaderSource(shaderId, "void main(void){gl_Position = ftransform();}"); // GL20.glShaderSource(shaderId, "#version 140\n" // + "\n" // + "uniform Transformation {\n" // + " mat4 projectionMatrix;\n" // + " mat4 viewMatrix;\n" // + " mat4 modelMatrix;\n" // + "};\n" // + "in vec4 in_Position;\n" // + "\n" // + "in vec3 vertex;\n" // + "\n" // + "void main() {\n" // + " gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_Position;\n" // + "}"); // GL20.glShaderSource(shaderId, "#version 150 core\n" // + "\n" // + "uniform mat4 projectionMatrix;\n" // + "uniform mat4 viewMatrix;\n" // + "uniform mat4 modelMatrix;\n" // + "\n" // + "in vec4 in_Position;\n" // + "in vec4 in_Color;\n" // + "in vec2 in_TextureCoord;\n" // + "\n" // + "out vec4 pass_Color;\n" // + "out vec2 pass_TextureCoord;\n" // + "\n" // + "void main(void) {\n" // + " gl_Position = in_Position;\n" // + " gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_Position;\n" // + "\n" // + " pass_Color = in_Color;\n" // + " pass_TextureCoord = in_TextureCoord;\n" // + "}"); GL20.glCompileShader(shaderId); GL20.glAttachShader(programId, shaderId); // int shaderId2 = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); // GL20.glShaderSource(shaderId2, "#version 150 core\n" // + "\n" // + "uniform sampler2D texture_diffuse;\n" // + "\n" // + "in vec4 pass_Color;\n" // + "in vec2 pass_TextureCoord;\n" // + "\n" // + "out vec4 out_Color;\n" // + "\n" // + "void main(void) {\n" // + " out_Color = pass_Color;\n" // + " // Override out_Color with our texture pixel\n" // + " out_Color = vec4(0.5, 0.5, 0.5, 1); //texture2D(texture_diffuse, pass_TextureCoord);\n" // + "}"); // GL20.glCompileShader(shaderId2); // GL20.glAttachShader(programId, shaderId2); GL20.glLinkProgram(programId); ErrorChecker.exitOnOpenGlError("Program linking."); System.err.println(GL20.glGetProgramInfoLog(programId, 255)); System.err.println(); GL20.glValidateProgram(programId); ErrorChecker.exitOnOpenGlError("Program validation."); camera = new Camera(width / (float) height, new Vector3f(0, 0, 2.5f), 100f, 60f, 0.1f, programId); ErrorChecker.exitOnOpenGlError("Camera creation."); sphere = new Sphere(60, 0.5f); sphere.create(programId); ErrorChecker.exitOnOpenGlError("Sphere creation."); }
From source file:org.jogamp.glg2d.impl.shader.AbstractShaderPipeline.java
License:Apache License
protected int compileShader(int type, ByteBuffer src) throws ShaderException { int id = GL20.glCreateShader(type); GL20.glShaderSource(id, src); int err = GL11.glGetError(); if (err != GL11.GL_NO_ERROR) { throw new ShaderException("Shader source failed, GL Error: 0x" + Integer.toHexString(err)); }/* w w w. jav a 2 s. c om*/ GL20.glCompileShader(id); err = GL11.glGetError(); if (err != GL11.GL_NO_ERROR) { throw new ShaderException("Compile failed, GL Error: 0x" + Integer.toHexString(err)); } return id; }
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public void shaderSource(int shader, String string) { GL20.glShaderSource(shader, string); }
From source file:org.spout.engine.renderer.shader.ShaderHelper.java
License:Open Source License
public static int compileShader(String source, int type) { int shader = GL20.glCreateShader(type); GL20.glShaderSource(shader, source); GL20.glCompileShader(shader);//from w w w. ja va2 s .c o m int status = GL20.glGetShader(shader, GL20.GL_COMPILE_STATUS); if (status != GL11.GL_TRUE) { String error = GL20.glGetShaderInfoLog(shader, 255); throw new ShaderCompileException("Compile Error in " + ((type == GL20.GL_FRAGMENT_SHADER) ? "Fragment Shader" : "VertexShader") + ": " + error); } return shader; }
From source file:org.terasology.rendering.assets.GLSLShaderProgramInstance.java
License:Apache License
private void compileShader(int type, int featureHash) { int shaderId = GL20.glCreateShader(type); StringBuilder shader = createShaderBuilder(); // Add the activated features for this shader for (int i = 0; i < ShaderProgramFeatures.FEATURE_ALL.ordinal(); ++i) { if ((ShaderProgramFeatures.values()[i].getValue() & featureHash) > 0) { shader.append("#define ").append(ShaderProgramFeatures.values()[i].name()).append("\n"); }/*from w w w .j ava 2s . co m*/ } shader.append("\n"); shader.append(includedDefines); shader.append(includedUniforms); if (type == GL20.GL_FRAGMENT_SHADER) { shader.append(includedFunctionsFragment).append("\n"); } else { shader.append(includedFunctionsVertex).append("\n"); } if (type == GL20.GL_FRAGMENT_SHADER) { shader.append(shaderProgramBase.getFragShader()); } else if (type == GL20.GL_VERTEX_SHADER) { shader.append(shaderProgramBase.getVertShader()); } String debugShaderType = "UNKNOWN"; if (type == GL20.GL_FRAGMENT_SHADER) { fragmentPrograms.put(featureHash, shaderId); debugShaderType = "FRAGMENT"; } else if (type == GL20.GL_VERTEX_SHADER) { vertexPrograms.put(featureHash, shaderId); debugShaderType = "VERTEX"; } // Dump all final shader sources to the log directory try { final String strippedTitle = shaderProgramBase.getTitle().replace(":", ""); File file = new File(PathManager.getInstance().getLogPath(), debugShaderType.toLowerCase() + "_" + strippedTitle + "_" + featureHash + ".glsl"); FileWriter fileWriter = new FileWriter(file); BufferedWriter out = new BufferedWriter(fileWriter); out.write(shader.toString()); out.close(); } catch (Exception e) { logger.error("Failed to dump shader source."); } GL20.glShaderSource(shaderId, shader.toString()); GL20.glCompileShader(shaderId); StringBuilder error = new StringBuilder(); boolean success = printLogInfo(shaderId, error); String errorLine = ""; if (error.length() > 0) { try { Pattern p = Pattern.compile("-?\\d+"); Matcher m = p.matcher(error.toString()); int counter = 0; while (m.find()) { if (counter++ % 2 == 1) { int lineNumberInt = Integer.valueOf(m.group()); Scanner reader = new Scanner(shader.toString()); for (int i = 0; i < lineNumberInt - 1; ++i) { reader.nextLine(); } errorLine = reader.nextLine(); errorLine = "Error prone line: '" + errorLine + "'"; logger.warn("{}", error); logger.warn("{}", errorLine); break; } } } catch (Exception e) { // Do nothing... } } if (!success) { String errorMessage = debugShaderType + " Shader '" + shaderProgramBase.getTitle() + "' failed to compile. Terasology might not look quite as good as it should now...\n\n" + error + "\n\n" + errorLine; logger.error("{}", errorMessage); JOptionPane.showMessageDialog(null, errorMessage, "Shader compilation error", JOptionPane.ERROR_MESSAGE); } }