Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 breakcode   Members   -  Reputation: 104

Like
0Likes
Like

Posted 27 June 2014 - 03:14 PM

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.



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8276

Like
1Likes
Like

Posted 27 June 2014 - 04:10 PM

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


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Buckeye   Crossbones+   -  Reputation: 6288

Like
1Likes
Like

Posted 27 June 2014 - 07:05 PM

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, 27 June 2014 - 07:32 PM.

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


#4 imoogiBG   Members   -  Reputation: 1247

Like
0Likes
Like

Posted 29 June 2014 - 08:20 AM

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, 29 June 2014 - 08:22 AM.


#5 Buckeye   Crossbones+   -  Reputation: 6288

Like
1Likes
Like

Posted 29 June 2014 - 09:28 AM

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.

 

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, 29 June 2014 - 09:42 AM.

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS