3dexperiments/src/engine/screen.js

36 lines
598 B
JavaScript

/* global alert */
class Screen {
constructor () {
this._el = document.createElement('canvas')
this.resize()
this._gl = this._el.getContext('webgl')
if (!this._gl) {
alert('Your machine or browser does not support WebGL!')
return
}
document.body.appendChild(this._el)
window.addEventListener('resize', (e) => {
this.resize()
}, false)
}
get gl () {
return this._gl
}
get ctx () {
return this._gl
}
resize () {
this._el.width = window.innerWidth
this._el.height = window.innerHeight
}
}
export default Screen