import * as _shaders from "./shaders.js"
import * as _mesh from "./mesh.js"
import * as _camera from "./camera.js"
/*function drawScene(gl, shader, camera, mesh) {
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clearDepth(1.0);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.useProgram(shader.program);
camera.use(gl, shader);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
function main() {
const canvas = document.querySelector("#glCanvas");
const gl = canvas.getContext("webgl")
if(gl == null) {
alert("Unable to initialize WebGL.");
return;
}
const shader = _shaders.init(gl);
const mesh = new _mesh.Mesh(gl, 2);
const camera = new _camera.Camera(gl, 45, 0.1, 1000.0);
camera.setpos(vec3.create(0, 0, -6.0));
mesh.add_positions(gl,
[-1.0, 1.0,
1.0, 1.0,
-1.0, -1.0,
1.0, -1.0]);
mesh.addattrib(gl, shader, mesh.posbuffer, 2, gl.FLOAT, false, 0, 0);
drawScene(gl, shader, camera, mesh);
console.log(mesh);
console.log(camera);
console.log(shader);
}*/
main();
//
// Start here
//
function main() {
const canvas = document.querySelector('#glCanvas');
const gl = canvas.getContext('webgl');
// If we don't have a GL context, give up now
if (!gl) {
alert('Unable to initialize WebGL. Your browser or machine may not support it.');
return;
}
// Vertex shader program
const shader = _shaders.init(gl);
const mesh = new _mesh.Mesh(gl, 2);
const camera = new _camera.Camera(gl);
const positions = [
1.0, 1.0,
-1.0, 1.0,
1.0, -1.0,
-1.0, -1.0,
];
mesh.add_positions(gl, positions);
drawScene(gl, shader, camera, mesh);
}
function drawScene(gl, shader, camera, mesh) {
gl.clearColor(0.0, 0.0, 0.0, 1.0); // Clear to black, fully opaque
gl.clearDepth(1.0); // Clear everything
gl.enable(gl.DEPTH_TEST); // Enable depth testing
gl.depthFunc(gl.LEQUAL); // Near things obscure far things
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
mesh.addattrib(gl, shader, mesh.posbuffer, 2, gl.FLOAT, false, 0, 0);
gl.useProgram(shader.program);
camera.use(gl, shader);
{
const offset = 0;
const vertexCount = 4;
gl.drawArrays(gl.TRIANGLE_STRIP, offset, vertexCount);
}
}
//window.onload = main;