jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
245 stars 43 forks source link

Effects #75

Open kennetherland opened 2 years ago

kennetherland commented 2 years ago

Got it working if you are interested:

#include "stdafx.h"
#include "Effect.h"
#include "d2d1effects.h"
#include "d2d1_1.h";

HANDLE CreateEffect(HANDLE ctx, REFCLSID effect)
{
    RetrieveContext(ctx);

    ID2D1HwndRenderTarget* renderTarget = (ID2D1HwndRenderTarget*) context->renderTarget;
    ID2D1Effect* compositeEffect;
    ID2D1DeviceContext* deviceContext;
    HRESULT hr;

    hr = renderTarget->QueryInterface(&deviceContext);

    hr = deviceContext->CreateEffect(effect, &compositeEffect);

    return (HANDLE)compositeEffect;
}

void SetInput(HANDLE d2dEffect, INT index, HANDLE d2dbitmap, BOOL invalidate)
{
    ID2D1Effect* effect = reinterpret_cast<ID2D1Effect*>(d2dEffect);
    ID2D1Bitmap* bitmap = reinterpret_cast<ID2D1Bitmap*>(d2dbitmap);

    effect->SetInput(index, bitmap, invalidate);
}
jingwood commented 2 years ago

@kennetherland Thanks so much! It would be great if you could consider making a PR for this.

60