Question

I am looking 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 to use gl_Color on my WebGL. I got an error that gl_Color is undeclared identifier.

What did I do wrong?

Thanks in advance for your help.

Was it helpful?

Solution

WebGL uses Open GL ES 2.0 as its base, therefore you should be using GLSL ES 1.0 for the shaders. GLSL ES does not have a gl_Color, and therefore you will have to rewrite this shader.

OTHER TIPS

My guess is that you're trying to compile GLSL code using a regular C compiler.

It looks like it's supposed to be C code, but it is actually GLSL source - deisgned to be compiled by the OpenGL GLSL compiler, not your machine C compiler.

The fragment shader has a pre-defined variable 'gl_Color' which is the output from the vertex shader.

The sample you reference has the code inside a shader.frag file, which is referenced by shader.init(). The OpenGL library itself will handle compiling it into GPU instructions for your machine. Put the code in that file, and hopefully the example will work :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top