DirectX 9 Present (render) video frame to specific location to HWND leaving existing window contents untouched

Started by
3 comments, last by Buckeye 9 years, 9 months ago

I am trying to do something specific using the DirectX 9 APIs in my application.

When I setup the directx device it requires a window handle (HWND) which ultimately the graphics driver ends up knowing about and using. What I am trying to do is inside the given window handle just have the graphics driver render to ONLY a specific portion of the window and leave the rest of the window untouched. For example. Let's say my window size is 1280x720 and I only want the video frame to render and present to a location inside the window of say 300x200. What is the best way using the Directx 9 API to do this leaving all the rest of the window untouched? I have the device all setup and I can already render video just fine to the entire window, but I am trying now to render to a window handle that already contains contents and specifies to me where I should render my video frame on the same window.

I notice that even if I specify to present to a subset location of the window on the first call to PresentEx() it blacks out the entire window, and then displays my frame when I make the call to PresentEx().

I am wondering if there is a way to tell the graphics driver or DirectX runtime (not sure who is doing it) NOT to black out everything else in that window? Initially this window has some HTML elements created and I am trying to not have the driver clobber the rest of the window.

I thought about somehow having the entire back buffer present to the window but somehow making a portion of the buffer where I don't want to draw to transparent, but I do not konw how to achieve this either. Thanks for any help.

Advertisement

Instead of rendering to the window, create a child control and use the HWND of that.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Take a look at the docs for Present. The second parameter is the destination rectangle in the window client area.

You can size your backbuffer to (for instance) 300x200 (or any size greater than that actually), set the viewport width and height to 300 & 200 (if you want to limit the backbuffer drawing area), and present from a 300x200 rectangle of the backbuffer (parameter 1 of Present) to a 300x200 rectangle within the window's client area (parameter 2 of Present).

You can do other drawing to the client area with whatever you want**, before or after you do your DX drawing and presentation, provided those areas are outside of the area that will be affected by Present. Provided the window frame isn't moved or resized (which would normally cause the client area to be erased), you're good to go.

EDIT: **Disclaimer - Admittedly, I've not done that sort of thing with video in the client area. And some video does funny things with video memory. The above approach is easy enough to try.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


I am wondering if there is a way to tell the graphics driver or DirectX runtime (not sure who is doing it) NOT to black out everything else in that window? 

this is maybe caused by the Clear function?

SetViewport function migth help?

http://msdn.microsoft.com/en-us/library/windows/desktop/bb174469(v=vs.85).aspx

Or Im not understanding the question at all?

The viewport determines only which portion of the backbuffer is rendered. The Present parameters (as mentioned above) determine which portion of the window client the backbuffer is blt'd to.

[attachment=22383:dx9present_area.png]

As shown here, the backbuffer is presented to just an area of the window - i.e., the second parameter of device->Present() is not NULL but a pointer to a RECT which is (more or less) centered in the window client.

If the second Present parameter is smaller than the client area, the remainder of client area remains as was drawn by any previous client-area drawing and is not affected by anything done to the backbuffer. That drawing is commonly controlled by a response to WM_PAINT. If the window was created with CS_HREDRAW | CS_VREDRAW style, then the client area is cleared to the background brush specified in the WNDCLASS structure. Those style flags cause the window to be redrawn (without regard to any DirectX settings) if the window is moved or is resized in the horizontal or vertical directions (respectively).

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement