gl-transition
a light function to render a GL Transition frame with a WebGLRenderingContext
.
The library adopts stack.gl style.
The only dependency is gl-shader.
The only assumption is that you have used bindBuffer
with "a-big-triangle" buffer (a triangle that covers the surface) so we internally will do drawArrays(gl.TRIANGLES, 0, 3)
.
short example
;const transition = ;transition;
API
The library exports this createTransition
function:
gl: WebGLRenderingContext transition: TransitionObjectLike options: Options = {} // renders one frame of the transition (up to you to run the animation loop the way you want) draw: progress: number from: GLTextureLike to: GLTextureLike width: number = gldrawingBufferWidth height: number = gldrawingBufferHeight params: key: string: number | boolean | GLTextureLike = {} void // dispose and destroy all objects created by the function call. void
where types are:
type TransitionObjectLike = glsl: string defaultParams: key: string: mixed paramsTypes: key: string: string ; type GLTextureLike = number shape: number number; type Options = resizeMode?: "cover" | "contain" | "stretch";
full example
;;; const imageFrom = await ;const imageTo = await ;// ^ NB: we just assumed you have these 2 imageFrom and imageTo Image objects that have the image loaded and ready const canvas = document;documentbody;canvaswidth = 500;canvasheight = 400; const gl = canvas || canvas;gl;const buffer = gl;gl;gl;gl; const from = ;fromminFilter = glLINEAR;frommagFilter = glLINEAR; const to = ;tominFilter = glLINEAR;tomagFilter = glLINEAR; const transition = ; // https://github.com/gl-transitions/gl-transitions/blob/master/transitions/cube.glsl // animates forever!const loop = { ; transition;};