Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
8 replies to this topic

#1   Members   -  Reputation: 1084

Like
0Likes
Like

Posted 22 October 2013 - 11:09 AM

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?



#2   Senior Moderators   -  Reputation: 7668

Like
0Likes
Like

Posted 22 October 2013 - 11:16 AM

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, 22 October 2013 - 11:16 AM.

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.
ScapeCode - Blog | SlimDX


#3   Members   -  Reputation: 1084

Like
0Likes
Like

Posted 22 October 2013 - 11:19 AM

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



#4   Senior Moderators   -  Reputation: 7668

Like
0Likes
Like

Posted 22 October 2013 - 11:21 AM

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, 22 October 2013 - 11:21 AM.

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.
ScapeCode - Blog | SlimDX


#5   Members   -  Reputation: 1084

Like
0Likes
Like

Posted 22 October 2013 - 11:36 AM

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.



#6   Members   -  Reputation: 849

Like
2Likes
Like

Posted 22 October 2013 - 11:42 AM

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, 22 October 2013 - 11:45 AM.


#7   Crossbones+   -  Reputation: 1590

Like
0Likes
Like

Posted 22 October 2013 - 11:54 AM

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



#8   Members   -  Reputation: 1084

Like
0Likes
Like

Posted 22 October 2013 - 01:01 PM


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!



#9   Members   -  Reputation: 849

Like
0Likes
Like

Posted 22 October 2013 - 01:29 PM

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






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS