开发者

unable to load json file into webgl code using request.open("GET", "cube.json");

开发者 https://www.devze.com 2023-03-26 17:21 出处:网络
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

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


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

    request.open("GET", "cube.json");

to

    request.open("GET", "cube.json", false);

You can find the documentation for XMLHttpRequest at http://www.w3.org/TR/XMLHttpRequest/

0

精彩评论

暂无评论...
验证码 换一张
取 消