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:fr.ign.cogit.geoxygene.util.gl.GLProgram.java
License:Open Source License
/** * Try to create a compiled vertex shader * //from w w w .ja v a2s.c o m * @param shaderContent * shader content as string * @param filename * file containing the shader content. It can be null, it is used * only to display the filename when an error occured * @return the shader id * @throws GLException * on shader creation error */ public static final int createVertexShader(String shaderContent, String filename) throws GLException { return GLTools.createShader(GL20.GL_VERTEX_SHADER, shaderContent, filename); }
From source file:lessur.util.shader.ShaderManager.java
License:GNU General Public License
/** * Fetches a shader id for a given vertex shader, generating * a new id if necessary./*from w w w . j av a2 s .c o m*/ * @param fragmentFileName The path to the vertex shader * @returns shaderID The shader ID of the [new] fragment shader */ public int getVertexShaderID(String vertexShaderFilePath) throws Exception { Integer id = shaderMap.get(vertexShaderFilePath); if (id == null) { if (has_opengl2) { id = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); GL20.glShaderSource(id, getProgramCode(vertexShaderFilePath)); GL20.glCompileShader(id); shaderMap.put(vertexShaderFilePath, id); } else if (has_arb) { id = ARBShaderObjects.glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB); ARBShaderObjects.glShaderSourceARB(id, getProgramCode(vertexShaderFilePath)); ARBShaderObjects.glCompileShaderARB(id); shaderMap.put(vertexShaderFilePath, id); } StringBuilder errorMessage = new StringBuilder(); //Check for errors with shader if (!compiledSuccessfully(id)) { errorMessage.append("Vertex Shader "); errorMessage.append(vertexShaderFilePath); errorMessage.append(" failed to compile.\n"); errorMessage.append(getShaderInfoLog(id)); errorMessage.append("\n\n"); errorMessage.insert(0, "Could not compile shader.\n"); throw new Exception(errorMessage.toString()); } } return id; }
From source file:main.java.com.YeAJG.game.gfx.ShaderHandler.java
License:Open Source License
public static int loadShader(String path) { int id = 0;// w ww . j a v a 2 s . c o m if (Shaders.containsKey(path)) return getShader(path); try { id = FileIOHandler.loadShader(path, GL20.GL_VERTEX_SHADER); Shaders.put(path, id); } catch (IOException ex) { logger.error(ex.getMessage()); } return id; }
From source file:model.ModelMD2.java
public void setupShader() { vsId = ShaderUtils.makeShader(ShaderUtils.loadText("Resources/shaders/animation.vert"), GL20.GL_VERTEX_SHADER); // Load the fragment shader fsId = ShaderUtils.makeShader(ShaderUtils.loadText("Resources/shaders/animation.frag"), GL20.GL_FRAGMENT_SHADER);//from www .j av a 2 s.c o m // Create a new shader program that links both shaders shader_id = ShaderUtils.makeProgram(vsId, fsId); GL20.glBindAttribLocation(shader_id, 0, "in_Position_0"); GL20.glBindAttribLocation(shader_id, 1, "in_TextureCoord_0"); GL20.glBindAttribLocation(shader_id, 2, "in_Normal_0"); GL20.glBindAttribLocation(shader_id, 3, "in_Position_1"); GL20.glBindAttribLocation(shader_id, 4, "in_TextureCoord_1"); GL20.glBindAttribLocation(shader_id, 5, "in_Normal_1"); GL20.glValidateProgram(shader_id); GLUtil.cerror(getClass().getName() + " setupShader"); }
From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java
License:Apache License
/** Loads and compiles the shaders, creates a new program and links the shaders. * /*from ww w.j a v a 2 s. com*/ * @param vertexShader * @param fragmentShader */ private void compileShaders(String vertexShader, String fragmentShader) { vertexShaderHandle = loadShader(GL20.GL_VERTEX_SHADER, vertexShader); fragmentShaderHandle = loadShader(GL20.GL_FRAGMENT_SHADER, fragmentShader); if (vertexShaderHandle == -1 || fragmentShaderHandle == -1) { isCompiled = false; return; } program = linkProgram(); if (program == -1) { isCompiled = false; return; } isCompiled = true; fetchAttributes(); fetchUniforms(); }
From source file:opengl.test.object.object.java
protected final void vertexShader(String file) { this.vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); GL20.glShaderSource(this.vertexID, object.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 ww .j ava 2 s. co m*/ GL20.glAttachShader(this.programID, this.vertexID); }
From source file:opengl.test.object.tree.testobject.leaf.java
private void vertexShader(String file) { this.vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); GL20.glShaderSource(this.vertexID, leaf.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 ww . j a v a 2s . co m*/ GL20.glAttachShader(this.programID, this.vertexID); }
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"); }// www.java2s . com GL20.glAttachShader(this.programID, this.vertexID); }
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"); }/*from www. j av a 2 s. c om*/ GL20.glAttachShader(this.programID, this.vertexID); }
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 . ja va 2 s. 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."); }