Skip to content

Commit e29ce17

Browse files
vedhantstalgiag
authored andcommitted
Add image() for webgl mode (#3634)
* Add image() for webgl mode * Reset instance properties after drawing image() in WEBGL mode * Remove translation of image
1 parent 4e74366 commit e29ce17

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/webgl/3d_primitives.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,4 +1541,50 @@ p5.RendererGL.prototype.curveVertex = function() {
15411541
}
15421542
};
15431543

1544+
p5.RendererGL.prototype.image = function(
1545+
img,
1546+
sx,
1547+
sy,
1548+
sWidth,
1549+
sHeight,
1550+
dx,
1551+
dy,
1552+
dWidth,
1553+
dHeight
1554+
) {
1555+
this._pInst.push();
1556+
1557+
this._pInst.texture(img);
1558+
this._pInst.textureMode(constants.NORMAL);
1559+
1560+
var u0 = 0;
1561+
if (sx <= img.width) {
1562+
u0 = sx / img.width;
1563+
}
1564+
1565+
var u1 = 1;
1566+
if (sx + sWidth <= img.width) {
1567+
u1 = (sx + sWidth) / img.width;
1568+
}
1569+
1570+
var v0 = 0;
1571+
if (sy <= img.height) {
1572+
v0 = sy / img.height;
1573+
}
1574+
1575+
var v1 = 1;
1576+
if (sy + sHeight <= img.height) {
1577+
v1 = (sy + sHeight) / img.height;
1578+
}
1579+
1580+
this.beginShape();
1581+
this.vertex(dx, dy, 0, u0, v0);
1582+
this.vertex(dx + dWidth, dy, 0, u1, v0);
1583+
this.vertex(dx + dWidth, dy + dHeight, 0, u1, v1);
1584+
this.vertex(dx, dy + dHeight, 0, u0, v1);
1585+
this.endShape(constants.CLOSE);
1586+
1587+
this._pInst.pop();
1588+
};
1589+
15441590
module.exports = p5;

0 commit comments

Comments
 (0)