There are two such shaders:

// Vertex shader program var VSHADER_SOURCE = 'attribute vec4 a_Position;\n' + 'attribute vec4 a_Color;\n' + 'varying vec4 v_Color;\n' + // varying variable 'void main() {\n' + ' gl_Position = a_Position;\n' + ' gl_PointSize = 10.0;\n' + ' v_Color = a_Color;\n' + // Pass the data to the fragment shader '}\n'; // Fragment shader program var FSHADER_SOURCE = '#ifdef GL_ES\n' + 'precision mediump float;\n' + // Precision qualifier (See Chapter 6) '#endif GL_ES\n' + 'varying vec4 v_Color;\n' + // Receive the data from the vertex shader 'void main() {\n' + ' gl_FragColor = v_Color;\n' + '}\n'; 

gl.getShaderParameter(shader, gl.COMPILE_STATUS); function: gl.getShaderParameter(shader, gl.COMPILE_STATUS);

The vertex shader is assembled without problems , but not fragmentary. This is what comes to the console: Failed to compile shader: ERROR: 0:3: 'GL_ES' : unexpected token after conditional expression

The code of someone else and I do not understand these lines here:

 '#ifdef GL_ES\n' + 'precision mediump float;\n' + '#endif GL_ES\n' + 

At first I sinned on a video card but she had nothing to do with it. This code is taken from the source of the book and no one spoke badly about it on the network.

Help me find the cause of the error.

    1 answer 1

    Try changing the lines to:

     '#ifdef GL_ES\n' + 'precision mediump float;\n' + '#endif\n' + 

    These lines switch the accuracy of calculations to the average for WebGL, since, it seems, not all devices support high accuracy by hardware , and those that support still work more slowly.

    • the fact of the matter is if you leave only the macro body, then everything works, and without it you can’t explain why the control structure of the macro does not work. - perfect
    • by the way your code is identical to mine. - perfect
    • @perfect, no, pay attention to the third line. Must be #endif instead of #endif GL_ES . Just now, just in case, I checked on jsfiddle - the same mistake, if you write like yours. - Surfin Bird
    • yes indeed if this line is changed then everything starts working. thank you for help. - perfect