@@ -2715,6 +2715,27 @@ void PApplet::image(PImage* img, float x, float y, float w, float h) {
27152715 if (!img || img->width ==0 || img->height ==0 ) return ;
27162716 drawImage_impl (img, x, y, w, h);
27172717}
2718+ // Nine-argument form: image(img, dx1,dy1,dx2,dy2, sx1,sy1,sx2,sy2)
2719+ void PApplet::image (PImage* img, float dx1,float dy1,float dx2,float dy2,
2720+ float sx1,float sy1,float sx2,float sy2) {
2721+ if (!img || img->width ==0 || img->height ==0 ) return ;
2722+ if (img->dirty ) img->uploadTexture ();
2723+ if (img->texID ==0 ) return ;
2724+ // Convert source pixel coords to UV [0,1]
2725+ float u1=sx1/img->width , v1=sy1/img->height ;
2726+ float u2=sx2/img->width , v2=sy2/img->height ;
2727+ glEnable (GL_BLEND ); glBlendFunc (GL_SRC_ALPHA ,GL_ONE_MINUS_SRC_ALPHA );
2728+ glEnable (GL_TEXTURE_2D ); glBindTexture (GL_TEXTURE_2D ,img->texID );
2729+ glColor4f (doTint?tintR:1 .f ,doTint?tintG:1 .f ,doTint?tintB:1 .f ,doTint?tintA:1 .f );
2730+ glBegin (GL_QUADS );
2731+ glTexCoord2f (u1,v1); glVertex2f (dx1,dy1);
2732+ glTexCoord2f (u2,v1); glVertex2f (dx2,dy1);
2733+ glTexCoord2f (u2,v2); glVertex2f (dx2,dy2);
2734+ glTexCoord2f (u1,v2); glVertex2f (dx1,dy2);
2735+ glEnd ();
2736+ glBindTexture (GL_TEXTURE_2D ,0 ); glDisable (GL_TEXTURE_2D ); glDisable (GL_BLEND );
2737+ glColor4f (1 .f ,1 .f ,1 .f ,1 .f );
2738+ }
27182739
27192740void PApplet::imageMode (int m){currentImageMode=m;}
27202741void PApplet::tint (float gray) {tint (gray, colorMaxA);}
0 commit comments