我正在试验 http://www.learningwebgl.com 中提供的代码,并且我专门尝试加载我有一个 json 图像,它与我的 html 文件位于同一目录中,但它没有被加载,
代码是:-
http://www.pasteall.org/23783
在 http://www.learningwebgl .com 我从第 14 课中获取了加载茶壶的代码,并在第 1 课中使用了它。
我开始认为问题可能是我在加载文件之前就绘制了对象。
当我尝试使用 firebug 进行调试时,出现错误,指出我的变量应该保存我正在加载的立方体的顶点位置,但未定义,
我不是专家,因此调试困扰着我。
等待答复
谢谢
I was experimenting with the code provided in http://www.learningwebgl.com and i was specifically trying to load a json image that resides in the same directory as my html file, but it is not getting loaded,
the code is :-
http://www.pasteall.org/23783
In http://www.learningwebgl.com i took the code that loaded a Teapot from lesson 14 and used it in Lesson 1.
I am starting to think the problem maybe that I am drawing the object even before the file is loaded.
When i tried to debug using firebug am getting an error saying that my variable that is supposed to hold the vertex positions of the cube that i am loading is not defined
I am not an expert so debugging is bugging me.
Waiting for an answer
Thanks
发布评论
评论(1)
您的问题听起来像是由于
XMLHttpRequest
是异步的(即request.send()
启动读取,但不等待其完成)。更改为同步 json 加载
尝试通过将行
您可以在 http://www.w3.org/TR/XMLHttpRequest/
Your problem sounds like it is due to the fact that
XMLHttpRequest
is asynchronous (i.e.request.send()
initiates a read, but does not wait for it to finish).Try making the json load synchronous by changing the line
to
You can find the documentation for
XMLHttpRequest
at http://www.w3.org/TR/XMLHttpRequest/