Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Project / Project.html
diff options
context:
space:
mode:
Commit74f7343e14addefc74446c19018b3f82ad961207 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-02-09 10:58:45 +0200
Committer
 Syndamia <kamen@syndamia.com>
2023-02-09 10:58:45 +0200
Files888066413efb35a762056537670f13294fa93286 /Year 2/Computer Graphics with WebGL/Project/Project.html
uni-projects-74f7343e14addefc74446c19018b3f82ad961207.tar
uni-projects-74f7343e14addefc74446c19018b3f82ad961207.tar.gz
uni-projects-74f7343e14addefc74446c19018b3f82ad961207.zip
Parent7cc99d560d3f36996dde0f73becd57445fc54d11 (diff)
[WGL/P] Added initial setup
1 files changed, 89 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Project/Project.html89
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html
new file mode 100644
index 0000000..a9e1d66
--- /dev/null
+++ b/Year 2/Computer Graphics with WebGL/Project/Project.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+
+<head>
+ <meta charset="utf-8"/>
+ <title>Черната дупка</title>
+
+ <script src="webgl-fmi.js"></script>
+ <script src="shaders.js"></script>
+
+ <style>
+canvas {
+ display: block;
+ position: fixed;
+ border: 1px solid black;
+ width: calc(100vw - 18px);
+ height: calc(100vh - 18px);
+}
+ </style>
+
+ <script>
+ function start()
+ {
+ var canvas = document.getElementById("picasso");
+ canvas.addEventListener('webglcontextlost',function(event){event.preventDefault();},false);
+ canvas.addEventListener('webglcontextrestored',function(){init();},false);
+
+ init();
+ }
+
+ function init()
+ {
+ gl = getContext("picasso");
+ glprog = getProgram(vShader,fShader);
+ getVariables();
+
+ gl.enable(gl.DEPTH_TEST);
+ gl.clearColor(1,1,1,1);
+
+ identity();
+ perspective(30,gl.canvas.width/gl.canvas.height,1,40000);
+ gl.uniform1i(uUseNormalMatrix,false);
+
+ gl.uniform3f(uAmbientColor,0.3,0.3,0.3);
+ gl.uniform3f(uDiffuseColor,1,1,1);
+ gl.uniform3f(uLightDir,0,0,-1);
+
+ blackHole = new BlackHole([0,0,0], 1);
+ planet1 = new Sphere([-5,0,0], 0.5);
+ planet1.color = [1,0,0];
+
+ resizeglcanvas();
+ }
+
+ BlackHole = function(center, size) {
+ this.sphere = new Sphere(center, size);
+ }
+
+ BlackHole.prototype.draw = function() {
+ this.sphere.draw();
+ }
+
+ function resizeglcanvas() {
+ gl.canvas.width = gl.canvas.offsetWidth;
+ gl.canvas.height = gl.canvas.offsetHeight;
+ gl.viewport(0,0,gl.canvas.width,gl.canvas.height);
+
+ // var proj=orthoMatrix(gl.canvas.width,gl.canvas.height,-1000,1000);
+ // gl.uniformMatrix4fv(uProjectionMatrix,false,proj);
+
+ drawFrame();
+ }
+ window.onresize = resizeglcanvas;
+
+ function drawFrame()
+ {
+ gl.clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT);
+
+ lookAt([10, 0, 3], [0,0,0], [0,0,1]);
+ blackHole.draw();
+ planet1.draw();
+
+ requestAnimationFrame(drawFrame);
+ }
+ </script>
+</head>
+
+<body onload="start()">
+ <canvas id="picasso"></canvas>
+</body>