I wanted to test if my laptop can handle WebGL by loading examples from my instructor's webpage. The examples on the webpage worked fine, just showing a square within a square. I then decided to copy the exact codes into a notepad text editor, saved them as .js files, and did the same for the .html file. However, upon running the code, I encountered the error mentioned in the title above. When I checked "Inspect Element", the part of the code causing the error was:
var setupWebGL = function(canvas, opt_attribs) {
function showLink(str) {
var container = canvas.parentNode;
//Uncaught Type Error :Cannot Readproperty 'parentNode' of null
if (container) {
container.innerHTML = makeFailHTML(str);
}
};
if (!window.WebGLRenderingContext) {
showLink(GET_A_WEBGL_BROWSER);
return null;
}
var context = create3DContext(canvas, opt_attribs);
if (!context) {
showLink(OTHER_PROBLEM);
}
return context;
};
I'm unsure how to fix this error since the code worked perfectly on the instructor's website. There must be something crucial that I'm missing. If you need more information or details about the issue, please let me know. Thank you
<!DOCTYPE html>
<html>
<head>
<script id="vertex-shader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main()
{
g1_Position = vPosition;
}
...