Results 1 to 6 of 6

Thread: Problem with Binary XMLHttpRequest and WebGL buffers

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    5

    Problem with Binary XMLHttpRequest and WebGL buffers

    Hi all,

    I'm just getting into webGL and want to start loading binary data directly into buffers instead of translating JSON into arrayBuffers. I can load the data correctly into a buffer but when I try and set that buffer as current I get this error in Chrome:

    Uncaught TypeError: Type error


    Here's a code snippet, the webGL parts are based off Lesson 1:

    Code :
    function onLoad()
    {
    	var canvas = document.getElementById("lesson01-canvas");
    	initGL(canvas);
     
    	var xmlhttp = new XMLHttpRequest();
    	xmlhttp.open("GET", "cube.bm", true);
    	xmlhttp.responseType = "arraybuffer";
     
    	xmlhttp.onload = function() 
    	{
    		var buffer = xmlhttp.response;
    		gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
     
    		// Reading Data
    		var v1 = new Float32Array(buffer);
     
    		alert(v[0]);  // This works fine.
    	}
    	xmlhttp.send();
     
    }

    I guess I need a solid example of how to give the result of a binary XMLHttpRequest into an arrayBuffer correctly. This is a Chrome only thing, I know that Firefox has a different way of requesting binary data at the moment.

    Thanks!

    Ram

  2. #2
    Junior Member
    Join Date
    Jan 2011
    Posts
    5

    Re: Problem with Binary XMLHttpRequest and WebGL buffers

    Arrrg it wouldnt let me edit the orig post but here's a slight update to the code:

    Code :
    function onLoad()
    {
       var canvas = document.getElementById("lesson01-canvas");
       initGL(canvas);
     
       var xmlhttp = new XMLHttpRequest();
       xmlhttp.open("GET", "cube.bm", true);
       xmlhttp.responseType = "arraybuffer";
     
       xmlhttp.onload = function()
       {
          var buffer = xmlhttp.response;
          gl.bindBuffer(gl.ARRAY_BUFFER, buffer); //  This causes an error
     
          // Reading Data
          var v1 = new Float32Array(buffer);
     
          alert(v1[0]);  // This works fine.
       }
       xmlhttp.send();
     
    }

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    17

    Re: Problem with Binary XMLHttpRequest and WebGL buffers

    If you're trying to open local file then add this parameter to the chrome:
    Code :
     --allow-file-access-from-files

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    5

    Re: Problem with Binary XMLHttpRequest and WebGL buffers

    No it's not a file issue, I can open the file correctly and I've tested that the binary data I receive is correct, the problem is getting that binary data into webGL. But thanks for the reply!

  5. #5
    Junior Member
    Join Date
    Jan 2011
    Posts
    5

    Re: Problem with Binary XMLHttpRequest and WebGL buffers

    I have yet to actually try and render anything but this at least doesn't generate any JS errors:

    Code :
    function onLoad()
    			{
    				var canvas = document.getElementById("lesson01-canvas");
    		    	initGL(canvas);
     
    				var xmlhttp = new XMLHttpRequest();
    				xmlhttp.open("GET", "cube.bm", true);
    				xmlhttp.responseType = "arraybuffer";
     
    				xmlhttp.onload = function() 
    				{					
    					var XHR_buffer = xmlhttp.response;
    					var GL_Buffer = gl.createBuffer();
     
    					gl.bindBuffer(gl.ARRAY_BUFFER, GL_Buffer);			    	
     
    					gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(XHR_buffer), gl.STATIC_DRAW);
     
    					// Reading Data
    					var v1 = new Float32Array(XHR_buffer);
    					alert(v1[0]);					
    			  	}
    				xmlhttp.send();
     
    			}

    Thank goes out to cultureulterior and his/her blog:
    http://calumnymmo.wordpress.com/2010/12 ... comment-12

  6. #6
    Junior Member
    Join Date
    Jan 2011
    Posts
    5

    Re: Problem with Binary XMLHttpRequest and WebGL buffers

    I can confirm this actually renders something.

Similar Threads

  1. Pre-Z problem in WebGL.
    By oak3d in forum WebGL - General
    Replies: 3
    Last Post: 08-18-2011, 09:15 AM
  2. webGL texturing problem
    By stefomitev in forum Developers Coding:Beginner
    Replies: 1
    Last Post: 05-30-2011, 03:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •