Sign in to follow this  

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

This topic is 1262 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Edited by Buckeye

Share this post


Link to post
Share on other sites
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?

Edited by imoogiBG

Share this post


Link to post
Share on other sites

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).

Edited by Buckeye

Share this post


Link to post
Share on other sites

This topic is 1262 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this