我通过以下方式逐步学习WebGL这本书 https://sites.google.com/site/webglbook/。我尝试通过使用缓冲区来绘制三个点(gl.ARRAY_BUFFER
)而不是循环(正如我之前在本书的其他示例中所做的那样)。
var u_FragColor = gl.getUniformLocation(gl.program, 'u_FragColor');
if(!u_FragColor){
console.log('Can\'t to get the "u_FragColor" variable.');
return -1;
}
// gl.uniform1f(u_FragColor, 1.0); // <- this variant doesn't work! Why?
gl.uniform4f(u_FragColor, 1.0, 0.0, 0.0, 1.0);
它工作正常,但我有一个关于gl_FragColor
初始化:为什么我不能替换
gl.uniform4f(u_FragColor, 1.0, 0.0, 0.0, 1.0);
on the
gl.uniform1f(u_FragColor, 1.0);
?我预计这也是一样的。但在这种情况下,我在控制台中收到错误: