Make a rectangle
This commit is contained in:
parent
54ff9106db
commit
07380c8c91
@ -113,6 +113,7 @@
|
|||||||
0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0,
|
||||||
1, 0, 0, 1, 0,
|
1, 0, 0, 1, 0,
|
||||||
1, 1, 0, 1, 1,
|
1, 1, 0, 1, 1,
|
||||||
|
0, 1, 0, 0, 1,
|
||||||
]);
|
]);
|
||||||
const vertexStride = 4 * 5;
|
const vertexStride = 4 * 5;
|
||||||
const positionOffset = 0;
|
const positionOffset = 0;
|
||||||
@ -122,6 +123,14 @@
|
|||||||
const positionLocation = gl.getAttribLocation(program, "position");
|
const positionLocation = gl.getAttribLocation(program, "position");
|
||||||
const textureCoordLocation = gl.getAttribLocation(program, "textureCoord");
|
const textureCoordLocation = gl.getAttribLocation(program, "textureCoord");
|
||||||
|
|
||||||
|
let indexBuffer = gl.createBuffer();
|
||||||
|
let indices = new Uint16Array([
|
||||||
|
0, 1, 2,
|
||||||
|
3, 0, 2,
|
||||||
|
]);
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||||
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
||||||
|
|
||||||
// Load texture
|
// Load texture
|
||||||
let image = document.getElementById("image");
|
let image = document.getElementById("image");
|
||||||
loadTexture(gl, image);
|
loadTexture(gl, image);
|
||||||
@ -139,7 +148,7 @@
|
|||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
||||||
gl.enableVertexAttribArray(positionLocation);
|
gl.enableVertexAttribArray(positionLocation);
|
||||||
gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, vertexStride, positionOffset);
|
gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, vertexStride, positionOffset);
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
gl.enableVertexAttribArray(textureCoordLocation);
|
gl.enableVertexAttribArray(textureCoordLocation);
|
||||||
gl.vertexAttribPointer(textureCoordLocation, 2, gl.FLOAT, false, vertexStride, textureCoordOffset);
|
gl.vertexAttribPointer(textureCoordLocation, 2, gl.FLOAT, false, vertexStride, textureCoordOffset);
|
||||||
|
Loading…
Reference in New Issue
Block a user