DirectX 콘텐츠가 바탕 화면과 실행중인 다른 응용 프로그램 위에 떠있는 것처럼 보입니다. 나는 또한 directx 내용을 반투명하게 만들 필요가 있으므로 다른 것들도 보여줄 수 있어야한다. 이 일을하는 방법이 있습니까?투명한 창에 투명 DirectX 콘텐츠를 그리려면 어떻게해야합니까?
C#으로 Managed DX를 사용하고 있습니다.
DirectX 콘텐츠가 바탕 화면과 실행중인 다른 응용 프로그램 위에 떠있는 것처럼 보입니다. 나는 또한 directx 내용을 반투명하게 만들 필요가 있으므로 다른 것들도 보여줄 수 있어야한다. 이 일을하는 방법이 있습니까?투명한 창에 투명 DirectX 콘텐츠를 그리려면 어떻게해야합니까?
C#으로 Managed DX를 사용하고 있습니다.
OregonGhost에서 제공하는 링크부터 Vista에서 작동하는 솔루션을 발견했습니다. 이것은 C# 구문의 기본 프로세스입니다. 이 코드는 Form을 상속하는 클래스에 있습니다. UserControl에서 작동하지 않는 것 같습니다.
//this will allow you to import the necessary functions from the .dll
using System.Runtime.InteropServices;
//this imports the function used to extend the transparent window border.
[DllImport("dwmapi.dll")]
static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins);
//this is used to specify the boundaries of the transparent area
internal struct Margins {
public int Left, Right, Top, Bottom;
}
private Margins marg;
//Do this every time the form is resized. It causes the window to be made transparent.
marg.Left = 0;
marg.Top = 0;
marg.Right = this.Width;
marg.Bottom = this.Height;
DwmExtendFrameIntoClientArea(this.Handle, ref marg);
//This initializes the DirectX device. It needs to be done once.
//The alpha channel in the backbuffer is critical.
PresentParameters presentParameters = new PresentParameters();
presentParameters.Windowed = true;
presentParameters.SwapEffect = SwapEffect.Discard;
presentParameters.BackBufferFormat = Format.A8R8G8B8;
Device device = new Device(0, DeviceType.Hardware, this.Handle,
CreateFlags.HardwareVertexProcessing, presentParameters);
//the OnPaint functions maked the background transparent by drawing black on it.
//For whatever reason this results in transparency.
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
// black brush for Alpha transparency
SolidBrush blackBrush = new SolidBrush(Color.Black);
g.FillRectangle(blackBrush, 0, 0, Width, Height);
blackBrush.Dispose();
//call your DirectX rendering function here
}
//this is the dx rendering function. The Argb clearing function is important,
//as it makes the directx background transparent.
protected void dxrendering() {
device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1.0f, 0);
device.BeginScene();
//draw stuff here.
device.EndScene();
device.Present();
}
마지막으로, 양식의 기본 설정이 부분적으로 투명한 유리처럼 보입니다. FormBorderStyle을 "none"으로 설정하면 내용 위에 100 % 투명하게 표시되어 모든 항목 위에 표시됩니다.
데스크톱 윈도우 관리자를 사용하지 않고, 즉 Windows XP를 지원하려는 경우 어려울 것이라고 생각합니다. DWM에서는 rather easy 인 것 같습니다.
속도가 문제가되지 않는다면 서페이스로 렌더링 한 다음 렌더링 된 이미지를 레이어 처리 된 창으로 복사 할 수 있습니다. 그렇게 빨리 기대하지 마라.
Vista의 DWM이 dx9이므로 dx9에서만 작동하는 고통. Windows 7은 dx10을 사용할 것이므로 좋을 것입니다. –
WPF 또한 옵션입니다.
Windows Presentation Foundation (또는 WPF)은 Windows 기반 응용 프로그램에서 사용자 인터페이스를 렌더링하기위한 컴퓨터 소프트웨어 그래픽 하위 시스템입니다.
이 링크가 질문에 대답 할 수 있지만 여기에 답의 핵심 부분을 포함하고 참조 용 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. – fglez
베타 테스트 중 약 4 년 전에 어떻게 답변을 받았는지 주목하십시오. 당시의 질문과 답변은 실험적이었습니다. 이것은 분명히 훌륭한 대답은 아니지만 대답과 그에 대한 실행 가능한 답변입니다. 링크는 내용 그대로 유효합니다. –
DirectComposition, LayeredWindows, DesktopWindowManager 또는 WPF를 사용할 수 있습니다. 모든 방법에는 장점과 단점이 있습니다.
-DirectComposition이 가장 효율적이지만 Windows 8이 필요하며 60Hz로 제한됩니다.
-LayeredWindows는 DXGI를 사용하는 Direct2D-interop을 통해 D3D로 작업하는 것이 까다 롭습니다.
-WPF는 D3DImage를 통해 비교적 쉽게 사용할 수 있지만 60Hz 및 DX9로 제한되며 MSAA는 없습니다. Interop에서 DXGI를 통한 상위 DX 버전까지 가능하며, 또한 MSAA-Rendertarget이 원시 nonAMSA 표면으로 해석 될 때 MSAA를 사용할 수 있습니다.
-DesktopWindowManager는 Windows Vista부터 사용할 수있는 고성능을 제공하지만 DirectX 버전은 DWM이 사용하는 버전 (여전히 Vista에서는 DX9)에 따라 제한적인 것처럼 보입니다. 가능한 경우 DXGI를 통해 상위 DX 버전에 대한 해결 방법을 사용할 수 있어야합니다.
픽셀 당 하나도 필요하지 않은 경우 반투명 형식의 불투명도 값을 사용할 수도 있습니다. 설명 된 모든 기술을 C # 및 SharpDX에서 사용할 수 있었지만 DirectComposition 및 LayeredWindows의 경우 약간의 C++ - Wrappercode가 필요했습니다. 우선 WPF를 통해 갈 것을 제안합니다.
레이어 창이 아닌 옵션이 있습니까? –
http://msdn.microsoft.com/en-us/library/ms997507.aspx –