Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Graphics Glitch depending on game view and screen size  (Read 4173 times)

0 Members and 1 Guest are viewing this topic.

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Graphics Glitch depending on game view and screen size
« on: May 09, 2016, 01:23:21 am »
The glitch is  pixels not stretching proportionally. The only way i found to avoid the issue it's to use view size thar are multiple of the screen size. For example:

window.setSize(1024, 768);
view.setSize(256, 192)

In this case the window is multiple of four. Other example is:

window.setSize(800, 600);
view.setSize(200, 150)

I'm using integer values in the view position.
« Last Edit: May 09, 2016, 01:26:00 am by Carlitox »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Graphics Glitch depending on game view and screen size
« Reply #1 on: May 09, 2016, 01:28:05 am »
Maybe add a bit more info to the problem description. It's not clear what's going wrong.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Graphics Glitch depending on game view and screen size
« Reply #2 on: May 09, 2016, 01:53:48 am »
It sounds to me like a problem of a texture (probably) being stretched without smoothing or anti-aliasing.
Basically, to increase the size of a texture, the only thing that can be done is to duplicate some of the current pixels. If you don't want it to double the original size, then it can't double all of the pixels so some stay "singled".
If this is a texture, you can fix this using texture smoothing:
texture.setSmooth(true);
This causes altered shades of the pixels to create a visual effect of a higher resolution.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Graphics Glitch depending on game view and screen size
« Reply #3 on: May 09, 2016, 02:25:24 pm »
This graphics are ok, all pixels have the same size.





Pixels with different sizes. It is caused when changing the window size horizontally or vertically. It happens resizing clicking on the windoiw borders and also resizing manually inside rezize event.




I've found that only works fine with this configuration.

window.setSize(1024, 768);
view.setSize(256, 192):


Smooth it's not good in a pixelated retro game.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Graphics Glitch depending on game view and screen size
« Reply #4 on: May 09, 2016, 02:32:10 pm »
What other result would you expect? Pixel is the base unit, you can't have one pixel stretched by a factor of x1.5, it is either x1 or x2.
Laurent Gomila - SFML developer

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Graphics Glitch depending on game view and screen size
« Reply #5 on: May 09, 2016, 05:01:17 pm »
What other result would you expect? Pixel is the base unit, you can't have one pixel stretched by a factor of x1.5, it is either x1 or x2.

What does it mean that?

Clicking to resize the window horizontally forces to choise between a multiple of the view like 1280x960 or 768x576? I use a 256 x 192 view. Using that sizes works.

If I'm right I have to avoid the mouse resizing option and doing it manually with an option inside the game. Using in the constructor of the window this styles:

window(game_screen_size, "Game", sf::Style::Close | sf::Style::Titlebar)

Another option is to use the sf::Event::Resized to control the window resizing calculating the size correctly.
« Last Edit: May 09, 2016, 05:15:17 pm by Carlitox »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Graphics Glitch depending on game view and screen size
« Reply #6 on: May 09, 2016, 06:42:16 pm »
Can you perhaps circle or somehow annotate the parts of your image that are messed up? I am not able to notice anything different by quickly glancing between the two.

Quote
Quote
What other result would you expect? Pixel is the base unit, you can't have one pixel stretched by a factor of x1.5, it is either x1 or x2.

What does it mean that?

I may be misunderstanding the problem, but imagine you have a window that is 10 pixels wide, and the pixels alternate between black and white. Now, if you were to stretch the window to 20 pixels wide, what would you expect? Each pixel will be "stretched" by a factor of 2 such that you now have 2 black pixels next to each other, then 2 white, then 2 black, etc. But what are you expecting to happen if you stretch the window to 13 pixels wide instead? It isn't possible to stretch each pixel by the same amount in this case.

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Graphics Glitch depending on game view and screen size
« Reply #7 on: May 09, 2016, 10:48:15 pm »



Look the black vertical lines in the red rectangle, they are bigger than the others.


There are some games that don't allow normal resizing, only to prefixed sizes like 800x600. Using multiples of my view solves the problem. But that forces me to use only a few sizes so doesn't allow custom sizes like other games.

I only need 3 sizes and the fullscreen mode, it's not a problem for me but i thing it's interesting to know the limitation.
« Last Edit: May 09, 2016, 10:56:33 pm by Carlitox »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Graphics Glitch depending on game view and screen size
« Reply #8 on: May 09, 2016, 11:56:44 pm »
Ok, thanks for the additional pictures. I figured this is the type of thing you were talking about, but I just couldn't spot the problem in your initial pictures.

Hopefully you understood the explanation for why this is happening at the bottom of my last post. One option you have for supporting additional resolutions is to just create different sets of sprites for them. For example, use one set of sprites for multiples of 1024x768 resolution, but if the user changes to 1920x1200, you can swap out your sprites for ones designed for that size. This would be more work of course, but it will allow you to support more resolution without worrying about how your sprites will looked when scaled.

 

anything