#### Archived

This topic is now archived and is closed to further replies.

# Anyone used PgBlt?

## Recommended Posts

paulbird    182
Has anyone ever got PgBlt(..) to work. It is supposed to draw a bitmap inside a polygon, specifically a rhombus. But I have never been able to get it to work. One of the arguments is a mono-bitmap for masking. Has anyone got an example of this function actually working?

#### Share this post

##### Share on other sites
Burning_Ice    122
the problem why this (and some other blit functions) dont work most of the time is that they need hardware support. i think with GetDeviceCaps you can check if your hardware supports the blit.
My voodoo3 doesnt support anything other then BitBlt

My Homepage

#### Share this post

##### Share on other sites
paulbird    182
My solution is to write my own PgBlt function to draw a DIB in a polygon with A being the top-left point B the top-tight and C the bottom left point of the polygon:

        void PgBlt(TDC *source, TDC *dest, TPoint pA,TPoint pB, TPoint pC){//get pointer to data of DIB   CreateCompatibleDIB(...,DIB_RGB,....,**data,....);//get pointer to data of output DIB   CreateCompatibleDIB(...,DIB_RGB,....,**data2,....);//or something like that similar.int a=pA.x, b=pB.x, c=pC.x;int A=pA.y, B=pB.y, C=pC.y;for(i=MIN(a,b,c);i<MAX(a,b,c);i++)  for(j=MIN(A,B,C);j<MAX(A,B,C);j++)     if( PixelIsInPolygon(i,j,pA,pB,pC) ){//find the co-ordinates of the soure bitmap to use         pixX=((i-A)*(c-a)-(C-A)*(j-a))/((B-A)*(c-a)-(C-A)*(b-a))*dib.Width();                 pixY=((B-A)*(j-a)-(i-A)*(b-a))/((B-A)*(c-a)-(C-A)*(b-a))*dib.Height();         int bit =pixX + pixY * dib.Width();       int bit2=i + j * dib2.Width();//set the RGB components of the output      data2[bit2*3+0] = data[bit*3+0];      data2[bit2*3+1] = data[bit*3+1];      data2[bit2*3+2] = data[bit*3+2];        }}

Or something like that. On a 500Mhz computer I think this would be fast enough for simple applications such as displaying a rotating bitmap. I haven't tried it yet. If someone wants to try it, and see if I made any mistakes here. You could try it with GetPixel() and SetPixel() but I have found them to be extremely slow.

[edited by - paulbird on April 28, 2003 1:15:45 PM]