1
\$\begingroup\$

I am making a game in monogame and have encountered the following problem:

My problem

The black arrows mark the places where the rendering is "off". As you can see the gray lines aren't "flush" or "smooth". Instead they have a "cut".

The two cuts at the top is at the same height, suggesting that an error happens with the positioning during drawing in that height. The two topmost cuts are 1 pixel off (from the cut and down) and the bottom cut is 1 pixel off compared to the texture but 2 pixels in total (again from cut and down). Furthermore, the cuts are always in the same place. The topmost cuts and the bottom cut are part of two different "draws" and happens even if the other is removed.

The background experiences this too some other places, but vertically and not horizontally as with the HUD.

This only happens in the resolution of 1920x1080 and not in any other I've tried. The problem fixes itself in fullscreen though.

What causes this and how do I fix it?

EDIT

The resolution is certainly 1920x1080. I've double checked that.

This is how i draw the gray frame at the top

spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);

spriteBatch.Draw(txtExpFrameLeft, new Vector2(0, 7), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.81f);

spriteBatch.End();

No resizing at all.

EDIT 2

Here is the result from the checker board:

enter image description here

As said, there are missing lines spread evenly around. When i move the gamecursor onto one of those "lines", it itself is also affected. Everything is still fine in fullscreen

\$\endgroup\$
  • \$\begingroup\$ Do you modify the state of these textures/objects between frames ? \$\endgroup\$ – Mateusz Feb 24 '17 at 16:52
  • \$\begingroup\$ No. The drawing is always the same. Nothin regarding the drawing changes between the frames. Even if I only draw the top-part with the two cuts (a single texture with no effects) and nothing else, the problem still persists. Do remember it only happens in one resolution without fullscreen \$\endgroup\$ – MasterXD Feb 24 '17 at 17:07
  • \$\begingroup\$ See this answer about scaling pixel art \$\endgroup\$ – DMGregory Feb 24 '17 at 20:16
  • \$\begingroup\$ As I've now added to the question, then I'm not scaling any of the textures. This should not result in any non-integer ratios for the scaling. Thank you for the link though, I lerned something new :D \$\endgroup\$ – MasterXD Feb 24 '17 at 23:40
1
\$\begingroup\$

Looks like you are drawing sprites with "nearest-neighbor" interpolation and sprite size on screen is set few pixels smaller than it should be.

Check your drawing dimensions, do you really output the images in their native size.

It could be that in windowed mode you still assume the canvas size (render area) is 1920x1080, while in fact it is smaller by windows borders.

\$\endgroup\$
  • \$\begingroup\$ What do you mean by "windows borders"? Borders of the "Windows Operative System Screen Borders", or the borders of the game window? If borders of game window: A white texture with the exact width of 1920 with a 1 pixel thick black vertical line in the far right end drawn in point (0,0) still reveals the black line. Thus the canvas size must be 1920 in width. Also, what is nearest-neighbor exactly and how do i disable/change it? I cant really find anything realated to my problem \$\endgroup\$ – MasterXD Feb 24 '17 at 21:56
  • \$\begingroup\$ I mean any kind of borders that factually reduce your render area down from 1920x1080. "A white texture with .. 1 pixel .. line in the far right" is a VERY bad test. To check for scaling effects you should be using black-n-white checkerboard pattern filling WHOLE texture (e.g. iubemcenter.indiana.edu/images/CheckerBoard.jpg). In your case - 1920x1080 checkerboard pixels. Any scaling effects will immediately show themselves in form of moir and "lost" lines. \$\endgroup\$ – Kromster says support Monica Feb 25 '17 at 6:57
  • \$\begingroup\$ Proper explanation is rather long to be put in comments. In short - nearest-neighbor scaling means that when scaled/resized, the nearest pixel is taken. So if source texture is 1080 in height and being rendered into 1070 area, everything looks normal, just 10 lines spread across height get skipped. (I believe your example shows exactly this happening) Same is true for when render area is 1090 - 10 lines get duplicated across the height. \$\endgroup\$ – Kromster says support Monica Feb 25 '17 at 7:05
  • \$\begingroup\$ I added the checkerboard and as you said, the lines was missing (See edit). So does this happen, because the game window is too large for my screens boundries (1920x1080) and thus tries to "fit" everything inside the smaller game window? \$\endgroup\$ – MasterXD Feb 25 '17 at 7:46
  • \$\begingroup\$ @MasterXD yes, and now you see it. \$\endgroup\$ – Kromster says support Monica Feb 25 '17 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.