Jump to content
  • Advertisement
Doommy

2D Going full screen using SharpDX (directx programming)

Recommended Posts

If someone could assist me through this I would be really grateful. I'm using SharpDX/C#/WinForms but I think this could more apply to directx in general.

I'm very new to graphics programming and I'm really just trying to do something as simple as displaying a rectangle to the screen.

Here is my issue:

I have the below code:

----------------------------------------------------------

 var desc = new SwapChainDescription()
            {
                BufferCount         = 1,
                ModeDescription     = new ModeDescription(1024, 768, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed          = false,
                OutputHandle        = form.Handle,
                SampleDescription   = new SampleDescription(1, 0),
                SwapEffect          = SwapEffect.Discard,
                Usage               = Usage.RenderTargetOutput
            };

I'm not sure if the window is loading in full screen. Actually to make it go full screen I actually have to set the forms property to: this.WindowState        = FormWindowState.Maximized; but that only seems lke Im using a C# code to maximize the form. For instance if I don't set the form to maximize, the form loads at the original size if IsWindowed is set to false. I recall with directx programing using dx7, when I set full screen you could actually see what looked like a display resolution change. I'm not seeing that. It pretty much looks like the form is loaded at the same size as the screen and not the value I provide in modeDescription. This is not what I want as well because I want to set the display to 1024x768 to avoid stretching of my graphics in wide screens.

Can someone help me make sense of this please.

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

Hello,

 

I am also using SharpDX but in the context of DX12. In my case I completely dropped native fullscreen support due to all the hassle I had with the swapchain changing state by itself without warning while there is still work queued that use the swapchain's buffer (when minimizing the application for example) and few more problems. 

 

However this is how I initially did it :

- Create the swapchain normally as you did. Make sure you give it the SwapChainFlags.AllowModeSwitch flag.

- Call the factory's MakeWindowAssociation method

- Call mySwapChain.SetFullscreenState() to make it go fullscreen.

- Resize the swapchain buffers to match the screen resolution.

 

This resource should also help you : https://stackoverflow.com/questions/25369231/properly-handling-alt-enter-alt-tab-fullscreen-resolution

Especially those part where I found out the hard way that they were actually true :

Spoiler

 

"This is going to be really tricky ... the right way how this is supposed to be handled is IDXGIFactory::MakeWindowAssociation, which, as far as I know, nobody has managed to use successfully. You may want to try it anyway."

"In general, real, exclusive fullscreen mode is not worth the trouble"

"A much better solution is to use a fullscreen borderless window. You simply create a window class without any decoration, make it full-screen, place it such that it covers the whole screen and be done with it"

 

 

I can see few way to get rid of the stretching other than going in exclusive mode. I'd first need to know how you expect it to look. Is a 1024x768 image centered in the middle of your 1920x1080 screen the end result you're looking for?

Edited by ChuckNovice

Share this post


Link to post
Share on other sites

Hi Chuck thanks for your help. With respect to:

"I can see few way to get rid of the stretching other than going in exclusive mode. I'd first need to know how you expect it to look. Is a 1024x768 image centered in the middle of your 1920x1080 screen the end result you're looking for?"

What I'm looking to do is put the form into full screen (maximized) so the full display is covered by the form window but the screen aspect ratio shows 4:3 so that I can place the image anywhere and have it show up not looking stretched. That is why I was looking at going full screen and having the display set to the resolution I wanted (1024x768) similar to the second picture in the attached image.

Right now I'm basically (for lack of doing it in SharpDX) setting the screen res outside of directx using code and then displaying my images and then reverting back to the current screen res after my program exists. What I want to do is initialize directx to create the window in the screen res I want holding the correct aspect ratio but I'm not seeming to do that.

 

image.bmp

Share this post


Link to post
Share on other sites

Pretty sure your problem is that you're missing the DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH flag. Not sure what that looks like in SharpDX though.

Share this post


Link to post
Share on other sites

I've updated the swap change description with that flag soldier and it still gives me the same results.

Share this post


Link to post
Share on other sites

Ah, now I understand what you're looking for, you want to avoid stretching. You're looking for DXGI_MODE_SCALING, but note that there's only STRETCH and CENTERED. Fullscreen exclusive doesn't give you the option for aspect ratio preserving stretch.

Sounds like you want a borderless fullscreen window, using DXGI flip model (FLIP_DISCARD instead of DISCARD), using DXGI_SCALING_ASPECT_RATIO_STRETCH. That's the only way I know of to get an aspect ratio preserve.

Share this post


Link to post
Share on other sites

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!