Gl_Color - undeclared identifier on WebGL

I look at http://www.swiftless.com/tutorials/glsl/3_glcolor.html , which has the following code snippet:

void main() { // Set the output color of our current pixel gl_FragColor = gl_Color;} 

I tried using gl_Color on my WebGL. I got an error that gl_Color is an undeclared identifier.

What have I done wrong?

Thanks in advance for your help.

+4
source share
2 answers

WebGL uses Open GL ES 2.0 as a base, so you should use GLSL ES 1.0 for shaders. GLSL ES does not have gl_Color, so you will have to rewrite this shader.

+8
source

I assume that you are trying to compile GLSL code using a regular C compiler.

It seems like it should be C-code, but in fact it is the source of GLSL that was compiled by the OpenGL GLSL compiler, and not the C compiler.

The fragment shader has a predefined variable 'gl_Color', which is the result of the vertex shader.

The sample you reference has code inside the shader.frag file referenced by shader.init (). The OpenGL library itself will handle the compilation in the GPU instructions for your computer. Put the code in this file and hopefully the example will work :)

-3
source

Source: https://habr.com/ru/post/1332454/


All Articles