Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- drawImage(
- tex, texWidth, texHeight,
- srcX, srcY, srcWidth, srcHeight,
- dstX, dstY, dstWidth, dstHeight, srcRotation) {
- var gl;
- var matrix, matrix2;
- var texMatrix;
- if (dstX === undefined) {
- dstX = srcX;
- srcX = 0;
- }
- if (dstY === undefined) {
- dstY = srcY;
- srcY = 0;
- }
- if (srcWidth === undefined) {
- srcWidth = texWidth;
- }
- if (srcHeight === undefined) {
- srcHeight = texHeight;
- }
- if (dstWidth === undefined) {
- dstWidth = srcWidth;
- srcWidth = texWidth;
- }
- if (dstHeight === undefined) {
- dstHeight = srcHeight;
- srcHeight = texHeight;
- }
- if (srcRotation === undefined) {
- srcRotation = 0;
- }
- gl = this._gl;
- gl.bindTexture(gl.TEXTURE_2D, tex);
- gl.useProgram(this._program);
- gl.bindBuffer(gl.ARRAY_BUFFER, this._positionBuffer);
- gl.enableVertexAttribArray(this._locations.position);
- gl.vertexAttribPointer(this._locations.position, 2, gl.FLOAT, false, 0, 0);
- gl.bindBuffer(gl.ARRAY_BUFFER, this._texcoordBuffer);
- gl.enableVertexAttribArray(this._locations.texcoord);
- gl.vertexAttribPointer(this._locations.texcoord, 2, gl.FLOAT, false, 0, 0);
- matrix = mat4.create();
- matrix2 = mat4.create();
- mat4.ortho(matrix, 0, 1000, 1000, 0, -1, 1);
- mat4.translate(matrix2, matrix, [dstX, dstY, 0]);
- mat4.copy(matrix, matrix2);
- mat4.scale(matrix2, matrix, [dstWidth, dstHeight, 1]);
- mat4.copy(matrix, matrix2);
- gl.drawingBufferHeight = 320;
- gl.uniformMatrix4fv(this._locations.matrix, false, matrix);
- texMatrix = mat4.create();
- mat4.fromScaling(texMatrix, [1 / texWidth, 1 / texHeight, 1]);
- mat4.translate(matrix2, texMatrix, [texWidth * 0.5, texHeight * 0.5, 0]);
- mat4.copy(texMatrix, matrix2);
- mat4.rotateZ(matrix2, texMatrix, srcRotation);
- mat4.copy(texMatrix, matrix2);
- mat4.translate(matrix2, texMatrix, [texWidth * -0.5, texHeight * -0.5, 0]);
- mat4.translate(texMatrix, matrix2, [srcX, srcY, 0]);
- mat4.scale(matrix2, texMatrix, [srcWidth, srcHeight, 1]);
- mat4.copy(texMatrix, matrix2);
- gl.uniformMatrix4fv(this._locations.textureMatrix, false, texMatrix);
- gl.uniform1i(this._locations.texture, 0);
- gl.drawArrays(gl.TRIANGLES, 0, 6);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement