import Renderer from './Renderer'; class Scene { private triangleVertexPositionBuffer: WebGLBuffer; private squareVertexPositionBuffer: WebGLBuffer; constructor(private r: Renderer) { this.triangleVertexPositionBuffer = r.createBuffer(); r.gl.bindBuffer(r.gl.ARRAY_BUFFER, this.triangleVertexPositionBuffer); const triangleVertices = [ -1.5, 1.0, -2.5, -1.0, -0.5, -1.0, ]; r.gl.bufferData(r.gl.ARRAY_BUFFER, new Float32Array(triangleVertices), r.gl.STATIC_DRAW); this.squareVertexPositionBuffer = r.createBuffer(); r.gl.bindBuffer(r.gl.ARRAY_BUFFER, this.squareVertexPositionBuffer); const squareVertices = [ 2.5, 1.0, 0.5, 1.0, 2.5, -1.0, 0.5, -1.0, ]; r.gl.bufferData(r.gl.ARRAY_BUFFER, new Float32Array(squareVertices), r.gl.STATIC_DRAW); } draw(): void { this.r.gl.clear(this.r.gl.COLOR_BUFFER_BIT | this.r.gl.DEPTH_BUFFER_BIT); this.r.gl.bindBuffer(this.r.gl.ARRAY_BUFFER, this.triangleVertexPositionBuffer); this.r.gl.vertexAttribPointer(this.r.vertexPosLoc, 2, this.r.gl.FLOAT, false, 0, 0); this.r.gl.drawArrays(this.r.gl.TRIANGLES, 0, 3); this.r.gl.bindBuffer(this.r.gl.ARRAY_BUFFER, this.squareVertexPositionBuffer); this.r.gl.vertexAttribPointer(this.r.vertexPosLoc, 2, this.r.gl.FLOAT, false, 0, 0); this.r.gl.drawArrays(this.r.gl.TRIANGLE_STRIP, 0, 4); } } export default Scene;