質問

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