As I embark on creating a basic application in WebGl and JavaScript following online tutorials, I encountered a peculiar issue while working on some fundamental shaders. The function responsible for generating the shader program presents itself as follows:
this.GenerateShaderProgram = function(vertexShader, fragmentShader)
{
var tempContainer = this.gl.createProgram();
var tempVertex = this.gl.createShader(this.gl.VERTEX_SHADER);
this.gl.shaderSource(tempVertex, vertexShader);
this.gl.compileShader(tempVertex);
if(!this.gl.getShaderParameter(tempVertex, this.gl.COMPILE_STATUS)) {
this.Log("invalid shader : " + vertexShader);
return null;
};
var tempFragment = this.gl.createShader(this.gl.FRAGMENT_SHADER);
this.gl.shaderSource(tempFragment, fragmentShader);
this.gl.compileShader(tempFragment);
if(!this.gl.getShaderParameter(tempFragment, this.gl.COMPILE_STATUS)) {
this.Log("invalid shader : " + fragmentShader);
return null;
};
this.gl.attachShader(tempContainer, tempVertex);
this.gl.attachShader(tempContainer, tempFragment);
return tempContainer;
}
The code for the two shaders is provided below:
attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
--------------------------------------------
#ifdef GL_ES precision highp float;
#endif
void main(void) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); };
The quirk lies in the fact that the first Vertex Shader compiles without any issues, but upon compiling the fragment shader it crashes at the line "this.gl.compileShader(tempFragment);" leaving me puzzled.