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

Started by
7 comments, last by Auskennfuchs 10 years, 5 months ago

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?

Advertisement
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

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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);

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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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.

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.

You have to resize all other buffers as well, such as depth buffer, back buffer and so on.


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!

You're welcome. Don't forget to also recalculate the projection matrices when start using them ;-)

This topic is closed to new replies.

Advertisement