I've managed to load a texture with TextureLoader.LoadFromFile(), and provided it with Color.Black.ToArgb() for it's colorkey.
Unfortunately, when I render it, using Device.DrawUserPrimitives, I'm still seeing black.
Am I missing some code to enable the use of the ColorKey?
Needed to set some renderstate on the Device:
Device.RenderState.AlphaBlendEnable = true;
Device.RenderState.SourceBlend = Blend.SourceAlpha;
Device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
I'm not certain which but I think you need to enable the render state(s) AlphaBlendEnable and/or AlphaTestEnable. You might also have to set the blend modes.
By the way, you're using Managed DirectX, which has long been discontinued. You should consider switching to XNA or SlimDX.
Related
I used in my Windows application(C#) GMAP API, I need to show the terrine feature of the map hence, I try to asssign the provider of the map as follow:
Map.MapProvider = GMapProviders.GoogleSatelliteMap;
unfortunately, the map didn't appear and show error as following:
How to get satellite view in C#??
check if you are in :
this is offline mode, it results to that if there are no caches.
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.CacheOnly;
if your map's zoom property is in 0, it will result to that. do this.
MainMap.Zoom=5; //country level zoom
EDIT: another thing, this is the code to view in satellite map.
MainMap.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
Try Newer Greatmap Release in Map
You should download the lastest version of GMap.Net from here:
https://www.nuget.org/packages/GMap.NET.Presentation/
I have a C# application which plays videos using the DirectShowNet library. When I debug my application using Visual C# on my laptop, the video is stretched to fit the container's dimensions i.e. the aspect ratio of the video is not maintained. When I load and run my application on a different computer (same operating system), the aspect ratio is maintained and black bars are created on the screen.
I do not want the aspect ratio to be maintained. I want the other computer to display the video the same way my computer is displaying it.
Why do you think the two computer's act differently and/or how do I fix this?
When I first saw this behaviour on the other computer, I updated that computer's DirectX to no avail. The exact same videos are being run on both systems.
EDIT #1: Could it possibly be some missing filter on the other computer? I assumed the default behaviour of DirectShow was not to maintain the Aspect Ratio.
EDIT #2: When I attempted to use IVMRWindowlessControl (VMR-7 & VMR-9), the cast from the VMR to the IVMRWindowlessControl kept on resulting in a NULL variable. As a result I tried IVMRAspectRatioControl with VMR-7 and it worked on one of the computers. The other computer stayed in Letterbox mode despite the call to remove the Aspect Ratio preservation.
EDIT #3: Here is the code using IVMRAspectRatioControl with VMR-7:
int hr = 0;
this.graphBuilder = (IGraphBuilder)new FilterGraph();
this.vmr = new VideoMixingRenderer();
this.graphBuilder.AddFilter((IBaseFilter)vmr, "VMR");
this.aspectRatioControl = (IVMRAspectRatioControl)this.vmr;
hr = this.aspectRatioControl.SetAspectRatioMode(VMRAspectRatioMode.None);
DsError.ThrowExceptionForHR(hr);
hr = this.graphBuilder.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
I am then using IVideoWindow to display the video.
When attempting to use the IVMRWindowlessControl9, the this.windowlessControl evaluated to NULL after the cast on the 4th line. I get the same NULL error when I tried it with VMR-7. The following uses VMR-9:
this.graphBuilder = (IGraphBuilder)new FilterGraph();
this.vmr = new VideoMixingRenderer9();
this.graphBuilder.AddFilter((IBaseFilter)vmr, "VMR");
this.filterConfig = (IVMRFilterConfig9)vmr;
hr = this.filterConfig.SetNumberOfStreams(1);
DsError.ThrowExceptionForHR(hr);
hr = this.filterConfig.SetRenderingMode(VMR9Mode.Windowless);
DsError.ThrowExceptionForHR(hr);
this.windowlessControl = (IVMRWindowlessControl9)this.vmr;
hr = this.windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.None);
DsError.ThrowExceptionForHR(hr);
hr = this.graphBuilder.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
I'm not entirely sure how it works, but could it be possible that the second computer does not support VMR-7 for the IVMRAspectRatioControl? The operating systems on both computers are the same, however the first computer (which works) is where I'm writing the software (it has the IDE). The second computer had a fresh install of Windows. On the second computer, I also updated DirectX as mentioned earlier.
Video renderers can be configured to preserve or not preserve aspect ratio. Configuration method (and, perhaps, default setting, which can also depend on internal mode of the renderer such as overlay/offscreen surface) is dependent on video renderer version you are using, e.g. for VMR-7 you will use IVMRWindowlessControl::SetAspectRatioMode's (or, IVMRAspectRatioControl::SetAspectRatioMode if your VMR is in windowed mode) DirectShow.NET equivalent/wrapper. VMR-9, EVR has similar methods.
With VMR-9 you will use IVMRAspectRatioControl9::SetAspectRatioMode. With EVR it is IMFVideoDisplayControl::SetAspectRatioMode.
If you don't want any letterboxing and aspect ration preservation, you just disable it explicitly when you set the video renderer up.
How to change screen orientation of each screen individually from C++ or C#? Having dual screen display configuration in mirror mode.
Intel Graphics card is installed on the machine. I tried EnumDisplaySettings function and DeviceMode structure. However, it only works in extended mode. If I try to change orientation by this function in mirror mode both screens are set to the same orientation. Maybe there is a way to change this settings through Intel driver SDK or any other native windows 7 functionality?
UPDATE 1:
Here is the code I tried with CCD API. It still rotates both displays =(
UINT32 PathArraySize = 0;
UINT32 ModeArraySize = 0;
DISPLAYCONFIG_PATH_INFO* PathArray;
DISPLAYCONFIG_MODE_INFO* ModeArray;
DISPLAYCONFIG_TOPOLOGY_ID CurrentTopology;
SetDisplayConfig(0,NULL,0,NULL,SDC_TOPOLOGY_CLONE|SDC_APPLY); //set to clone mode
GetDisplayConfigBufferSizes(QDC_ALL_PATHS, &PathArraySize, &ModeArraySize);
PathArray = (DISPLAYCONFIG_PATH_INFO*)malloc(PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
memset(PathArray, 0, PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
ModeArray = (DISPLAYCONFIG_MODE_INFO*)malloc(ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
memset(ModeArray, 0, ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
LONG ret = QueryDisplayConfig(QDC_DATABASE_CURRENT,&PathArraySize, PathArray, &ModeArraySize, ModeArray, &CurrentTopology);
PathArray++;
PathArray->targetInfo.rotation = DISPLAYCONFIG_ROTATION_ROTATE180; //set Second display rotated 180
PathArray--;
SetDisplayConfig(PathArraySize,PathArray,ModeArraySize,ModeArray, SDC_APPLY | SDC_SAVE_TO_DATABASE | SDC_ALLOW_CHANGES | SDC_USE_SUPPLIED_DISPLAY_CONFIG); //apply rotation
free(PathArray);
free(ModeArray);
You can try using the CCD APIs. These functions allows you to manipulate the VidPN topology for your current session. They aren't the easiest functions to call though.
Edit:
I don't see anything wrong with your code, apart from maybe the SDC_ALLOW_CHANGES flag. I tried your code on my system which has a Nvidia card. It does one of two things depends on which target I rotate. If I rotate the 2nd of the two targets, it ignores the change. In the Nvidia control panel, I can see the 2nd monitor is rotated, but its settings are greyed out. This suggests to me that the Nvidia driver doesn't support what you want to do. If I rotate the first target, it causes both targets to rotate. I've also tried changing the target scaling to DISPLAYCONFIG_SCALING_STRETCHED. That also made no difference. SetDisplayConfig returns 0. Windows at least seems to be happy with the change.
Have you tried to do what you want with the Intel display utility? If you can't do it with the Intel tool, then maybe the Intel driver doesn't support it. You probably want to ask someone from Intel on whether it is supported.
So this is a continuation of a question I asked earlier today. I've built myself some nice looking ribbon trails using XNA 3.1's DrawUserPrimitives method, essentially by expanding a polygon as motion occurs. It all looks super sleek and nice, except for one thing - anti-aliasing. I cannot for the life of me work out how to apply it.
I've set this in the game constructor:
graphics.PreferMultiSampling = true;
And I've also added this to test for the hardware:
graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>((sender, e) =>
{
PresentationParameters parameters = e.GraphicsDeviceInformation.PresentationParameters;
parameters.MultiSampleQuality = 0;
#if XBOX
pp.MultiSampleType = MultiSampleType.FourSamples;
return;
#else
int quality;
GraphicsAdapter adapter = e.GraphicsDeviceInformation.Adapter;
SurfaceFormat format = adapter.CurrentDisplayMode.Format;
if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, false, MultiSampleType.FourSamples, out quality))
{
parameters.MultiSampleType = MultiSampleType.FourSamples;
}
else if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, false, MultiSampleType.TwoSamples, out quality))
{
parameters.MultiSampleType = MultiSampleType.TwoSamples;
}
#endif
});
By adding some print lines, I know my hardware can support 4 sample AA, but this all seems to make no difference. I just can't seem to get this to work.
Here's a screenshot of one of my trails with all of that code applied:
I'd really appreciate some help. I looked at this a while ago for a solution to a different problem, and couldn't get it to work then, either.
Well, cheers.
Fixed this one, too!
The issue was that, while the back buffer was getting the right anti-alias settings, the render target wasn't. This meant that drawing to the render target was done without AA, but the texture that was then drawn to the back buffer was done with it. I've fixed it now.
I am using SlimDX with WinForms for a while now, but want to make the switch to WPF now. However, I can't figure out how to get DX10/11 working with WPF. The February release of SlimDX provides a WPF example, which only works with DX 9 though.
I found the following solution: http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx
but can't get it to work with SlimDX. My main problem is the shared resource handle as I don't know how to retrieve the shared handle from a SlimDX texture. I can't find any information to this topic.
In C++ the code looks like this:
HRESULT D3DImageEx::GetSharedHandle(IUnknown *pUnknown, HANDLE * pHandle)
{
HRESULT hr = S_OK;
*pHandle = NULL;
IDXGIResource* pSurface;
if (FAILED(hr = pUnknown->QueryInterface(__uuidof(IDXGIResource), (void**)&pSurface)))
return hr;
hr = pSurface->GetSharedHandle(pHandle);
pSurface->Release();
return hr;
}
Basically, what I want to do (because I think that this is the solution), is to share a texture between a Direct3d9DeviceEx (for rendering the WPF D3DImage) and a Direct3d10Device (a texture render target for my scene).
Any pointers in the right direction are greatly appreciated.
They posted some sample code on how to use slimdx/directx10 with WPF. Here's the link
There is a control called WindowsFormsHost, maybe you could integrate your current WinForm control that way?
Have a look at D3DImageEx. http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx
You provide a reference to your rendertarget, but it has to be created with the Shared flag. I was not able to use a swapchain in this way though.
let renderTargetDescription = Texture2DDescription( Width=width,
Height=height,
MipLevels=1,
ArraySize=1,
Format = Format.B8G8R8A8_UNorm,
SampleDescription = SampleDescription(Count = 1),
BindFlags = (BindFlags.RenderTarget ||| BindFlags.ShaderResource),
OptionFlags = ResourceOptionFlags.Shared)