List of usage examples for org.lwjgl.opengl GL20 GL_VERTEX_SHADER
int GL_VERTEX_SHADER
To view the source code for org.lwjgl.opengl GL20 GL_VERTEX_SHADER.
Click Source Link
From source file:com.github.begla.blockmania.rendering.ShaderManager.java
License:Apache License
private int createVertexShader(String filename, String title) { _vertexShader.put(title, GL20.glCreateShader(GL20.GL_VERTEX_SHADER)); if (_vertexShader.get(title) == 0) { return 0; }// w ww .j a va 2 s .c o m String fragCode = ""; String line; try { BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader .getResource("com/github/begla/blockmania/data/shaders/" + filename).openStream())); while ((line = reader.readLine()) != null) { fragCode += line + "\n"; } } catch (Exception e) { Blockmania.getInstance().getLogger().log(Level.SEVERE, "Failed to read vertex shader."); return 0; } GL20.glShaderSource(_vertexShader.get(title), fragCode); GL20.glCompileShader(_vertexShader.get(title)); printLogInfo(_vertexShader.get(title)); return _vertexShader.get(title); }
From source file:com.github.kajdreef.mazerunnermvn.MazeRunner.ShaderProgram.java
public void newShaderProgram(String vertexShaderLocation, String fragmentShaderLocation) { // Initialize the vertex Shader vertexId = compileShader(GL20.GL_VERTEX_SHADER, vertexShaderLocation); // Initialize the fragment shader fragmentId = compileShader(GL20.GL_FRAGMENT_SHADER, fragmentShaderLocation); programId = GL20.glCreateProgram();/*from w w w.jav a2s. c o m*/ GL20.glAttachShader(programId, vertexId); GL20.glAttachShader(programId, fragmentId); // Position information will be attribute 0 GL20.glBindAttribLocation(programId, 0, "in_Position"); // Color information will be attribute 1 GL20.glBindAttribLocation(programId, 1, "in_Color"); // Texture information will be attribute 2 GL20.glBindAttribLocation(programId, 2, "in_TextureCoord"); GL20.glLinkProgram(programId); GL20.glValidateProgram(programId); // Get matrices uniform locations projectionMatrixLocation = GL20.glGetUniformLocation(programId, "projectionMatrix"); viewMatrixLocation = GL20.glGetUniformLocation(programId, "viewMatrix"); modelMatrixLocation = GL20.glGetUniformLocation(programId, "modelMatrix"); }
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 w ww.j av a 2 s.co 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.github.ryancwilliams.WJ3dPL.graphics.GLUtils.ShaderProgram.java
License:Apache License
/** * Converts the provided shader type value to a string. * @param type the type value to convert. * @return the type value as a String./* w w w. j a v a 2 s.c o m*/ */ public static String typeToString(int type) { switch (type) { case GL20.GL_VERTEX_SHADER: return "GL_VERTEX_SHADER"; case GL20.GL_FRAGMENT_SHADER: return "GL_FRAGMENT_SHADER"; default: return "shader"; } }
From source file:com.google.gapid.glviewer.gl.Shader.java
License:Apache License
private boolean attachShaders(String vertexSource, String fragmentSource) { int vertexShader = createShader(GL20.GL_VERTEX_SHADER, vertexSource); if (vertexShader < 0) { return false; }// w ww . j av a 2 s.c o m int fragmentShader = createShader(GL20.GL_FRAGMENT_SHADER, fragmentSource); if (fragmentShader < 0) { GL20.glDeleteShader(vertexShader); return false; } GL20.glAttachShader(handle, vertexShader); GL20.glAttachShader(handle, fragmentShader); return true; }
From source file:com.grillecube.client.renderer.gui.ProgramColoredQuad.java
public ProgramColoredQuad() { super();// ww w . j a v a2s . c o m this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadColored.fs"), GL20.GL_FRAGMENT_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadColored.gs"), GL32.GL_GEOMETRY_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadColored.vs"), GL20.GL_VERTEX_SHADER)); this.link(); }
From source file:com.grillecube.client.renderer.gui.ProgramFont.java
public ProgramFont() { super();/*from w w w .ja v a2 s . co m*/ this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/font.fs"), GL20.GL_FRAGMENT_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/font.vs"), GL20.GL_VERTEX_SHADER)); this.link(); }
From source file:com.grillecube.client.renderer.gui.ProgramTexturedQuad.java
public ProgramTexturedQuad() { super();/* w ww . j a v a 2 s . c o m*/ this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadTextured.fs"), GL20.GL_FRAGMENT_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadTextured.gs"), GL32.GL_GEOMETRY_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quadTextured.vs"), GL20.GL_VERTEX_SHADER)); this.link(); }
From source file:com.grillecube.client.renderer.lines.ProgramLines.java
public ProgramLines() { super();//from w ww .j a v a 2 s . com this.addShader(GLH.glhLoadShader(R.getResPath("shaders/lines.fs"), GL20.GL_FRAGMENT_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/lines.vs"), GL20.GL_VERTEX_SHADER)); this.link(); }
From source file:com.grillecube.client.renderer.model.ProgramModel.java
public ProgramModel() { super();/*from w w w .j a va 2s .co m*/ this.addShader(GLH.glhLoadShader(R.getResPath("shaders/model.fs"), GL20.GL_FRAGMENT_SHADER)); this.addShader(GLH.glhLoadShader(R.getResPath("shaders/model.vs"), GL20.GL_VERTEX_SHADER)); this.link(); }