0

I'm adding Direct Draw rendering option to my 2D Graphics Engine.

When setting the Direct Draw Clipper on a non fullscreen application clipper clips the client area with an offset if the Window's client area top left position is not on the 0,0 of the screen.

Here is my clipper setup code :

LPDIRECTDRAWCLIPPER directDrawClipper = nullptr;
if (!FAILED(mDirectDraw->CreateClipper(0, &directDrawClipper, NULL))) {
    if (!FAILED(directDrawClipper->SetHWnd(0, App->getWindow()->getHandle()))) {
        if (!FAILED(mDirectDrawFrontBuffer->SetClipper(directDrawClipper))) {
            if (!FAILED(mDirectDrawBackBuffer->SetClipper(directDrawClipper))) {    
                return true; //all good
            } else {
                throw Error::Exception(L"DirectDraw arka görüntü bellek tamponu kesicisi kurulamadı", 
                                       L"Renderer Kurulum Hatası");
            }
        } else {
            throw Error::Exception(L"DirectDraw ana görüntü bellek tamponu kesicisi kurulamadı", 
                                   L"Renderer Kurulum Hatası");
        }
    } else {
        throw Error::Exception(L"DirectDraw kesicisi pencereye kurulamadı", 
                               L"Renderer Kurulum Hatası");
    }
} else {
    throw Error::Exception(L"DirectDraw kesicisi kurulamadı", 
                           L"Renderer Kurulum Hatası");
}
    

And here is the screenshot :

enter image description here

the size of the white areas are the distance of client area to the screen upper left corner.

Moving the window to upper left corner of the screen before setting the clipper and moving it back to original position doesn't help.

Thanks in advance.

Caner Kurt
  • 91
  • 1
  • 9
  • What window is `App->getWindow()`? It appears that it is not being moved together with your main window. – Vlad Feinstein Nov 18 '20 at 20:00
  • I only have one window and the window returned by the getWindow function is the main window – Caner Kurt Nov 18 '20 at 20:39
  • 1
    [DirectDraw](https://learn.microsoft.com/en-us/windows/win32/directdraw/directdraw) is pretty dated technology (*"DirectDraw is no longer recommended for use. With the release of Direct3D 9.0, all two-dimensional functionality is contained within Direct3D, its associated helper functions in D3DX, and the DirectX 11 technology Direct2D."*) Is there a specific reason for you to choose DirectDraw? – IInspectable Nov 18 '20 at 20:53
  • My Engine can also render with Direct2D, GDI, GDI+. There is no specific reason to add the DirectDraw rendering option. It's just for fun. – Caner Kurt Nov 18 '20 at 21:36
  • @CanerKurt Can this issue be reproduced using new technology like Direct3D? – Rita Han Nov 19 '20 at 09:46
  • My graphics engine already has new technology which is Direct2D. I don't need a clipper with GDI, GDI+ and Direct2D but a clipper is a must have when using DirectDraw because if the source rectangle is bigger than the client area DirectDraw doesn't even render at all. – Caner Kurt Nov 19 '20 at 17:29
  • and strangely DirectDraw gives better FPS compared with GDI, GDI+ and even Direct2D :) – Caner Kurt Nov 19 '20 at 18:37

1 Answers1

0

For the curious I solved the problem with a hack.

Before setting the clipper move the window to a position which the client area of the window will be on 0,0 of the screen. You can use ClientToScreen function to determine the window position which client area will be on the 0,0 of the screen.

After setting up the DirectDraw move the window back to it's original position but there is a problem, if you move the window immediately after setting up the DirectDraw issue persists. (I believe clipper setting functions works async). To solve that you can set a windows timer , right after setting the DirectDraw set a timer (1 second got the job done in my case) and move window back to it's original position when the timer updates.

To summarize the process :

  • Move window to a new position which client area of the window will be on the 0,0 of the screen.
  • Set up the clipper
  • Set a timer (1 second worked in my case)
  • When timer updates move window back the it's original position.

But still if someone knows the proper solution it would be nice.

Caner Kurt
  • 91
  • 1
  • 9