<!doctype html><html><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> <title>Map</title> <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/> <script src="http://cache.amap.com/lbs/static/es5.min.js"></script> <script src="http://webapi.amap.com/maps?v=1.3&key=123"></script> <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script></head><body><div id="container"></div><script> var map = new AMap.Map('container', { resizeEnable: true, zoom:11, center: [116.397421, 39.80923] });
map.on('moveend', function() {
var canvas = document.getElementsByClassName("amap-layer")[0]; var gl = canvas.getContext("webgl"); //var gl = canvas.getContext("webgl", {preserveDrawingBuffer: true});
//gl.clear(gl.COLOR_BUFFER_BIT);
var fb = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
var tex = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, tex); var width = 10; var height = 10; gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
var pixels = new Uint8Array(width * height * 4); gl.bindFramebuffer(gl.FRAMEBUFFER, null); gl.readPixels(10, 10, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels); console.log(pixels); });
</script></body></html>--
You received this message because you are subscribed to the Google Groups "WebGL Dev List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-list+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-lis...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-list+unsubscribe@googlegroups.com.
Your problem is:
var width = 10;
var height = 10;
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
...
gl.readPixels(10, 10, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
Since width and height are 10, your texture is 10x10, and your readpixel command is reading pixels between point (10,10) and (20,20). Since this is an out-of-bounds read, it either reads 0, or doesn't change the value of `pixels`. ArrayBuffers are initialized to zero, so either way, you'll only see zeros in the data after calling ReadPixels.
You want to use:
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);