cntools / rawdraw

Primitive Platform Agnostic Graphics Library
MIT License
407 stars 56 forks source link

Switch to Alpha Blitting in GDI #110

Open cnlohr opened 3 hours ago

cnlohr commented 3 hours ago

Just a feature that would be cool!

cnlohr commented 2 hours ago

I got this far, and it doesn't actually blend... not sure why. Anyone else, any ideas?

}

void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h )
{
    static int pbw, pbh;
    static HBITMAP pbb;
    if( !pbb || pbw != w || pbh !=h )
    {
        if( pbb ) DeleteObject( pbb );
        pbb = CreateBitmap( w, h, 1, 32, 0 );
        pbh = h;
        pbw = w;
    }

    int i;
    for( i = 0; i < w*h; i++ )
    {
        data[i] = rand() | 0x01000000; //(data[i] & 0xffffff ) | ((rand()&0xff)<<24);
    }

    SetBitmapBits(pbb,w*h*4,data);

    SelectObject( CNFGlsHDCBlit, pbb );
#ifdef GDI32NOUSEALPHA
    BitBlt(CNFGlsHDC, x, y, w, h, CNFGlsHDCBlit, 0, 0, SRCCOPY);
#else
    // If you use this, you will also need to link to -lmsimg32 
    static const BLENDFUNCTION BlendFunc = { .BlendOp = AC_SRC_OVER, .BlendFlags = 0, .SourceConstantAlpha = 255, .AlphaFormat = AC_SRC_ALPHA };    
    AlphaBlend( CNFGlsHDC, x, y, w, h, CNFGlsHDCBlit, 0, 0, w, h, BlendFunc );
#endif
}