Estoy tratando de ejecutar este código en un script json, es solo el código webgl. Estoy tratando de hacer que esto funcione, pero no es así. Estoy tratando de hacer un octágono usando múltiples triángulos, pero cuando intento crearlos con los índices, no funciona.
Creo que el problema está en el valor de los índices numItems. También se supone que debe mostrar un fondo negro, pero esto tampoco se muestra. ¿Alguna ayuda? (Este no es el código completo, pero creo que aquí es donde está el problema)
octagonIndexBuffer = gl.createBuffer(); // ** gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, octagonIndexBuffer); // We bind the IBO as an ELEMENT_ARRAY_BUFFER. let indexes = [ // The indexes that will be loaded in the buffer 0, 2, 4,//A 4, 0, 6,//B 6, 0, 7,//C 7, 0, 5,//D 5, 0, 3,//E 5, 0, 8,//F 8, 0, 9,//G 9, 0, 2//H ]; gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexes), gl.STATIC_DRAW); octagonIndexBuffer.itemSize = 1; // item size = 1 because one index = one vertex. octagonIndexBuffer.numItems = 24; octagonVertexColorBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, octagonVertexColorBuffer); // We define our vertex colors. let colors = [ 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ]; gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW); octagonVertexColorBuffer.itemSize = 4; // item size = 4 because (R, G, B, A). octagonVertexColorBuffer.numItems = 9; octagonVertexPositionBuffer = gl.createBuffer(); // We tell our GPU to create a buffer and give us a pointer to it. gl.bindBuffer(gl.ARRAY_BUFFER, octagonVertexPositionBuffer); // We need to bind the buffer (make it active) in order to use it. // We define our vertex positions. let vertices = [ 0.0, 0.0, 0.0, //1 1.0, 1.0, 0.0,//2 -1.0, 1.0, 0.0, //3 1.0, -1.0, 0.0,//4 -1.0, -1.0, 0.0, //5 0.5, -1.5, 0.0, //6 -0.5, -1.5, 0.0 , //7 -0.5, 1.5, 0.0 , //8 0.5, 1.5, 0.0 , //9 ]; gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); // We send the vertex positions to the buffer in our GPU. octagonVertexColorBufferVertexPositionBuffer.itemSize = 3; // item size = 3 because (x, y, z). octagonVertexPositionBuffer.numItems = 9; // numItems = 3 because we have three vertices.