Sign in to follow this  
NathanRidley

[SharpDX] Not sure why resizing my window causes jagged polygon edges

Recommended Posts

I've got a very simple learner app which simply renders a couple of triangles on the screen. Window resizing with the RenderForm works automatically but scales the viewport, meaning you get upscaled pixels when sizing up, and so forth. In order to handle resizing properly, I've tried to update the swap chain, render target and viewport when the window size changes, and this seems to work, as long as the aspect ratio is unchanged, but when the aspect ratio changes, the polygon edges seem to render poorly, with odd two-pixel jumps in the horizontal or vertical directions, even though I've enabled antialiasing.

 

My code is here: https://gist.github.com/axefrog/7104217

 

Before resizing:

 

2013-10-22_1807.png

 

After resizing:

 

2013-10-22_1808.png

 

Any idea what step I'm missing?

Share this post


Link to post
Share on other sites
Are you updating the viewport?

If not, then it is not getting updated, and thus the resulting image is scaled automatically to fit the window. THe scaling is pretty darned brute force, and thus has no prettyness smile.png Edited by Washu

Share this post


Link to post
Share on other sites

Are you updating the viewport?

If not, then it is not getting updated, and thus the resulting image is scaled automatically to fit the window. THe scaling is pretty darned brute force, and thus has no prettyness smile.png

 

Yep, line 74 in the code:

_viewport = new Viewport(0, 0, _form.ClientSize.Width, _form.ClientSize.Height);

Share this post


Link to post
Share on other sites
That's not updating it after a resize. That's only initializing it when the application starts.

When the form's size changes, you need to change the viewport to reflect the new size. Edited by Washu

Share this post


Link to post
Share on other sites

That's not updating it after a resize. That's only initializing it when the application starts.

When the form's size changes, you need to change the viewport to reflect the new size.

 

I'm fairly sure you didn't actually view the context surrounding line 74. You'll note that it sits inside the form resize handler.

Share this post


Link to post
Share on other sites

Just guessing, but you use _form.Width and .Height for your new SwapChainTarget-sizes. I think these values are the dimension of the full window including titlebar, border etc. You must use the clientarea-size of your form for correct width and height.

 

btw: In MSDN the ResizeEnd Event is also triggered when dragging on caption bar.

http://msdn.microsoft.com/de-de/library/system.windows.forms.form.resizeend.aspx

You may check this eventtype, too.

Edited by Auskennfuchs

Share this post


Link to post
Share on other sites


Just guessing, but you use _form.Width and .Height for your new SwapChainTarget-sizes. I think these values are the dimension of the full window including titlebar, border etc. You must use the clientarea-size of your form for correct width and height.

 

You sir, are correct! That solved the problem, thanks!

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

Sign in to follow this