Jump to content

Dmitry87

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by Dmitry87

  1. Hi,I'm writing some demos on JavaScript and get into some problems that can't understand how it works.I create a constructor function and define it variables and functions.But in InitBuffer function I'm calling onload image function and I'd like to be able to use this. variables but not what I did below. I create new variables image and sampTexture. Maybe I should pass that parameters in this onload function. But wasn't able to do that.

    function window(objectsSource){  this.xmlsource=objectsSource;  this.indexbuffer = null;  this.texelbuffer = null;  this.initbuffer = InitBuffer;							   function InitBuffer(){	var texels = getTexelsFromXML(this.xmlsource);												this.texelbuffer = gl.createBuffer();	gl.bindBuffer(gl.ARRAY_BUFFER, this.texelbuffer);											gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(texels), gl.STATIC_DRAW);	this.texelbuffer.itemSize = texels.itemSize;	this.texelbuffer.nItems = texels.nItems;	gl.vertexAttribPointer(shaderProgram.vertexTextureAttribute, this.texelbuffer.itemSize, gl.FLOAT, false, 0, 0);	this.texelbuffer.imageArray = gl.createTexture();														  	sampTexture = this.texelbuffer.imageArray;	this.texelbuffer.imageArray.image = new Image();	image = this.texelbuffer.imageArray.image;	this.texelbuffer.imageArray.image.onload = function(){																							  	try{																gl.bindTexture(gl.TEXTURE_2D, sampTexture);						gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);		gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);		gl.generateMipmap(gl.TEXTURE_2D);		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);	}	catch(e){	  alert("!!!");	}	image.src=texels.imageArray[0];

×
×
  • Create New...