Question

I want to draw a single colour cube in WebGL and I want to specify the color with in the fragment shader. I know that I can do that when I drawing a square. To eloborate my question can I avoid using the color buffer in the way that it is mention in this tutorial.

"MDN WebGl Tutorial"

Was it helpful?

Solution

If you really "want to specify the color within the fragment shader", this is your fragment shader:

precision mediump float;

void main(void) {
    gl_FragColor = vec4 (0.0, 1.0, 0.0, 1.0); 
}

This would give you green (values in the vec4() are r, g, b, a). Of course, in this case you can eliminate all the color stuff under the heading "Define the vertices' colors" in the tutorial.

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