sse2 / daisy

a simple, tiny, very fast, well-documented, header-only library for 2D primitive and text rendering using D3D9 & GDI, written in C++17
MIT License
26 stars 5 forks source link

Render state error #2

Closed ghost closed 1 year ago

ghost commented 1 year ago

Thanks for sharing this renderer

while using it, i noticed that upon utilizing it in a game internally (tf2), it messes up, specifically so (Black game background): fpXpuRvwZK

Code:

HRESULT D3DAPI hooks::end_scene ( IDirect3DDevice9* device ) {
    daisy::daisy_initialize ( device );
    daisy::daisy_prepare ( );

    daisy::c_renderqueue queue;
    if ( !queue.create ( 500 , 1000 ) )
        return EXIT_FAILURE;

    // push a filled triangle
    queue.push_filled_triangle ( { 0, 720 } , { 1280 / 2, 0 } , { 1280, 720 } , { 255, 0, 0, 72 } , { 0, 255, 0, 72 } , { 0, 0, 255, 72 } );

    // flushing of all render queues should happen here
    queue.flush ( );

    queue.clear ( );

    daisy::daisy_shutdown ( );

    return end_scene_o ( device );
}

Immediately I realized this is just a directx state issue, and i pasted this fix from UC:

https://www.unknowncheats.me/forum/counterstrike-global-offensive/292735-panorama-proper-rendering-fix.html

and this fixed the issue.

I thought I'd drop this here, I'm not sure if it's an error on my behalf or the renderer. Among other things, I tried to use daisy_prepare() before initializing, but I believe that just made me crash, so I thought i'd put this here

I also recognize my code is shit and I shouldn't be doing a lot of these calls in endscene on every frame, but this was just for testing purposes while setting up the lib

sse2 commented 1 year ago

Hey, sorry for the really late response, didn't see this until now.

If you plan on using this with a hijacked D3D9 device inside a hook like EndScene, you should (as stated in the post you linked) capture the device state alongside the current shaders and restore them after you're done rendering, before the original call. I didn't really bother including this in the library itself since it seemed somewhat outside the scope. Glad you fixed the issue.

Happy hacking!

ghost commented 1 year ago

It’s no problem, I figured it was beyond the scope of this library but thought I’d open it just in case someone might need it. Thanks!

On Tue, Jul 18, 2023 at 15:09 sse2 @.***> wrote:

Hey, sorry for the really late response, didn't see this until now.

If you plan on using this with a hijacked D3D9 device inside a hook like EndScene, you should (as stated in the post you linked) capture the device state alongside the current shaders and restore them after you're done rendering, before the original call. I didn't really bother including this in the library itself since it seemed somewhat outside the scope. Glad you fixed the issue.

Happy hacking!

— Reply to this email directly, view it on GitHub https://github.com/sse2/daisy/issues/2#issuecomment-1640828249, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUZXH3SRBAK772RZTNLTVQLXQ3NPFANCNFSM6AAAAAA2COJZQU . You are receiving this because you authored the thread.Message ID: @.***>