private boolean initProgram(GL3 gl3) { boolean validated = true; if (validated) { ShaderProgram shaderProgram = new ShaderProgram(); ShaderCode vertShaderCode = ShaderCode.create( gl3, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE, "vert", null, true); ShaderCode fragShaderCode = ShaderCode.create( gl3, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE, "frag", null, true); shaderProgram.init(gl3); shaderProgram.add(vertShaderCode); shaderProgram.add(fragShaderCode); programName = shaderProgram.program(); shaderProgram.link(gl3, System.out); } // Get variables locations if (validated) { uniformMvp = gl3.glGetUniformLocation(programName, "mvp"); uniformDiffuse = gl3.glGetUniformLocation(programName, "diffuse"); } return validated & checkError(gl3, "initProgram"); }
private boolean initProgram(GL3 gl3) { boolean validated = true; ShaderCode[] shaderCodes = new ShaderCode[Shader.MAX]; if (validated) { shaderCodes[Shader.VERT] = ShaderCode.create( gl3, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE, "vert", null, true); shaderCodes[Shader.FRAG] = ShaderCode.create( gl3, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE, "frag", null, true); ShaderProgram shaderProgram = new ShaderProgram(); shaderProgram.add(shaderCodes[Shader.VERT]); shaderProgram.add(shaderCodes[Shader.FRAG]); shaderProgram.init(gl3); programName = shaderProgram.program(); gl3.glBindAttribLocation(programName, Semantic.Attr.POSITION, "position"); gl3.glBindAttribLocation(programName, Semantic.Attr.TEXCOORD, "texCoord"); gl3.glBindFragDataLocation(programName, Semantic.Frag.COLOR, "color"); shaderProgram.link(gl3, System.out); } if (validated) { gl3.glUniformBlockBinding( programName, gl3.glGetUniformBlockIndex(programName, "Transform"), Semantic.Uniform.TRANSFORM0); gl3.glUseProgram(programName); gl3.glUniform1i(gl3.glGetUniformLocation(programName, "diffuse"), 0); gl3.glUseProgram(0); } return validated & checkError(gl3, "initProgram"); }
private void initProgram(GL3 gl3) { ShaderCode vertShader = ShaderCode.create( gl3, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_NAME, "vert", null, true); ShaderCode fragShader = ShaderCode.create( gl3, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_NAME, "frag", null, true); ShaderProgram shaderProgram = new ShaderProgram(); shaderProgram.add(vertShader); shaderProgram.add(fragShader); shaderProgram.init(gl3); programName = shaderProgram.program(); /** * These links don't go into effect until you link the program. If you want to change index, you * need to link the program again. */ gl3.glBindAttribLocation(programName, Semantic.Attr.POSITION, "position"); gl3.glBindAttribLocation(programName, Semantic.Attr.COLOR, "color"); gl3.glBindFragDataLocation(programName, Semantic.Frag.COLOR, "outputColor"); shaderProgram.link(gl3, System.out); /** * Take in account that JOGL offers a GLUniformData class, here we don't use it, but take a look * to it since it may be interesting for you. */ modelToClipMatrixUL = gl3.glGetUniformLocation(programName, "modelToClipMatrix"); vertShader.destroy(gl3); fragShader.destroy(gl3); checkError(gl3, "initProgram"); }
public LitProgram( GL3 gl3, String shadersFilepath, String vertexShader, String fragmentShader, int projectionUBB) { super(gl3, shadersFilepath, vertexShader, fragmentShader); unLocModelToCameraMatrix = gl3.glGetUniformLocation(getProgramId(), "modelToCameraMatrix"); unLocLightDiffuseIntensity = gl3.glGetUniformLocation(getProgramId(), "lightDiffuseIntensity"); unLocLightAmbientIntensity = gl3.glGetUniformLocation(getProgramId(), "lightAmbientIntensity"); unLocNormalModelToCameraMatrix = gl3.glGetUniformLocation(getProgramId(), "normalModelToCameraMatrix"); unLocLightCameraSpacePosition = gl3.glGetUniformLocation(getProgramId(), "cameraSpaceLightPosition"); unLocLightAttenuation = gl3.glGetUniformLocation(getProgramId(), "lightAttenuation"); unLocShininessFactor = gl3.glGetUniformLocation(getProgramId(), "shininessFactor"); unLocBaseDiffuseColor = gl3.glGetUniformLocation(getProgramId(), "baseDiffuseColor"); int projectionUBI = gl3.glGetUniformBlockIndex(getProgramId(), "Projection"); gl3.glUniformBlockBinding(getProgramId(), projectionUBI, projectionUBB); }