Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

body onload="" cannot find function

i am trying stuff with philogl library, and when i wrote,

<!DOCTYPE html>

<html>
<head>
    <title>PGL2</title>
    <script type="text/javascript" src="PhiloGL.js"></script>
    <script type="text/javascript">
    function webGLStart(){
        alert('I m alive');
    }
</script>
</head>

<body onload="webGLStart();">
<canvas id="c" style="width:500px; height:500px;"></canvas>


</body>
</html>

everything works fine, but if i write some philogl in it like,

<!DOCTYPE html>

<html>
<head>
    <title>PGL2</title>
    <script type="text/javascript" src="PhiloGL.js"></script>
    <script type="text/javascript">
    function webGLStart(){
        var triangle = new PhiloGL.O3D.Model({
            vertices: [[0,1,0],[-1,-1,0],[1,-1,0]],
            colors: [[1,0,0,1],[0,1,0,1],[0,0,1,1]]
            });
        var square = new PhiloGL.O3D.Model({
            vertices: [[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0]],
            colors: [[0.5,0.5,1,1],[0.5,0.5,1,1]],[0.5,0.5,1,1]
            });
    }
</script>
</head>

<body onload="webGLStart();">
<canvas id="c" style="width:500px; height:500px;"></canvas>


</body>
</html>

chrome and firefox gives me an error that says webGLStart() is not defined. What is wrong with my code?

like image 835
gkaykck Avatar asked Feb 24 '23 23:02

gkaykck


1 Answers

This line:

        colors: [[0.5,0.5,1,1],[0.5,0.5,1,1]],[0.5,0.5,1,1]

is syntactically incorrect: a closing "]" is in the wrong place. Thus the function definition "failed", so to speak, and the function doesn't really exist.

I literally just woke up so I'm not sure what's wrong with me that I could spot that.

like image 156
Pointy Avatar answered Mar 04 '23 22:03

Pointy