Answer the question
In order to leave comments, you need to log in
How to draw a texture in WebGL dynamically changing its transparency?
var alpha = ctx.globalAlpha;
//Below is the code from the webgl-2d library that draws the texture to the canvas
var shaderProgram = gl2d.initShaders(transform.c_stack, sMask);
vartexture = textureCache[cacheIndex];
gl.bindBuffer(gl.ARRAY_BUFFER, rectVertexPositionBuffer);
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 4, gl.FLOAT, false, 0, 0);
gl.bindTexture(gl.TEXTURE_2D, texture.obj);
gl.activeTexture(gl.TEXTURE0);
gl.uniform1i(shaderProgram.uSampler, 0);
sendTransformStack(shaderProgram);
gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
/*
How can I make the texture render with transparency,
which is set in the alpha variable, so that by changing this value in the game loop, the
texture smoothly appears or fades?
*/
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question