我尝试将顶点中的 z 更改为不同的数字,但它看起来与它为 0 时相同。我是一个视觉学习者,因此将不胜感激任何示例或视觉解释。
没有变化:
const vertices2 = [0, .4, 0,
-.6, .0, 0,
.6, 0, 0];
let dmColor2 =[1, 1, 1, 0, .5, 1, 0, .4,
.5, .5, 1, 0, .5, 1, 0, .4, 0,
0, .5, 1, 0, .5, 1, 0, .9, 0,
0, .5, 1, 0, .5, 1, 0, .9, 0];
//creates object2
dmVAO2 = gl.createVertexArray();
gl.bindVertexArray(dmVAO2);
dmVBO2 = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, dmVBO2);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices2), gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(0);
//creates color 2
dmColorBuffer2 = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, dmColorBuffer2);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(dmColor2), gl.STATIC_DRAW);
gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(1);
gl.bindVertexArray(dmVAO2);
gl.vertexAttrib1f(3, 1.0);
indices = [0, 1, 2];
gl.vertexAttrib3f(2, -1, 0, -1);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.DYNAMIC_DRAW);
gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT, 0);
并进行更改:
const vertices2 = [0, .4, .8,
-.6, .0, .8,
.6, 0, .8];
let dmColor2 =[1, 1, 1, 0, .5, 1, 0, .4,
.5, .5, 1, 0, .5, 1, 0, .4, 0,
0, .5, 1, 0, .5, 1, 0, .9, 0,
0, .5, 1, 0, .5, 1, 0, .9, 0];
//creates object2
dmVAO2 = gl.createVertexArray();
gl.bindVertexArray(dmVAO2);
dmVBO2 = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, dmVBO2);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices2), gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(0);
//creates color 2
dmColorBuffer2 = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, dmColorBuffer2);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(dmColor2), gl.STATIC_DRAW);
gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(1);
gl.bindVertexArray(dmVAO2);
gl.vertexAttrib1f(3, 1.0);
indices = [0, 1, 2];
gl.vertexAttrib3f(2, -1, 0, -1);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.DYNAMIC_DRAW);
gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT, 0);
我是做错了什么还是错过了什么,我真的不明白为什么它不起作用。无论哪种方式,看起来都像是一个二维的蓝色三角形。