문제

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"

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top