我正在尝试使用philogl库,当我写作时,
<!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>
Run Code Online (Sandbox Code Playgroud)
一切正常,但如果我在里面写一些philogl,
<!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>
Run Code Online (Sandbox Code Playgroud)
chrome和firefox给了我一个错误,说没有定义webGLStart().我的代码出了什么问题?
这一行:
colors: [[0.5,0.5,1,1],[0.5,0.5,1,1]],[0.5,0.5,1,1]
Run Code Online (Sandbox Code Playgroud)
在语法上是不正确的:结束"]"是在错误的地方.因此,功能定义"失败",可以说,功能并不存在.
我确实刚刚醒来,所以我不确定我能发现什么是错的.