SHARE
TWEET

Untitled

a guest Jan 20th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createTexture(gl, data) {
  2.     var stringData = String.fromCharCode.apply(null, new Uint16Array(data));
  3.     var encodedData = window.btoa(stringData);
  4.     var dataURI = "data:image/jpeg;base64," + encodedData;
  5.  
  6.     texture = gl.createTexture();
  7.     texture.image = new Image();
  8.  
  9.     texture.image.onload = function () {
  10.         gl.bindTexture(gl.TEXTURE_2D, texture);
  11.         gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
  12.         gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.image);
  13.         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  14.         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  15.         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  16.         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  17.         gl.bindTexture(gl.TEXTURE_2D, null);
  18.     };
  19.  
  20.     texture.image.src = dataURI;
  21.  
  22.     return texture;
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top