0
\$\begingroup\$

Force even resolution window

I am using GLFW/glfw3 OpenGL to write 2D games.

Some of my shaders have artifacts that only appear when the window size has an odd value. Eg 1201 by 1024 creates artifacts. 1200 by 1024 does not have artifacts.

The artifacts are unacceptable and must be fixed.

There are two solutions.

  1. Rewrite all the shaders (which I would like to avoid as the source of the artifact is that I use a lot of integers rather than floats. There is a lot to rewrite / redesign)

  2. And the easy quick fix... Ensure the screen size is always even.

    Example code;

    unsigned int windowWidth{wS->N->GetUInt("windowWidth")};
    unsigned int windowHeight{wS->N->GetUInt("windowHeight")};
    glfwCreateWindow(
         std::max(320, windowWidth / 2 * 2),   // even
         std::max(200, windowHeight / 2 * 2),  // even
         (const char*)&wS->N->GetString("appName")[0],
         NULL, NULL
     );
    

Question

Is there any reason to avoid forcing even resolutions / window size?

Fullscreen I believe is OK as I don't know of any display the has an odd dimension.

Will this cause problems in windowed mode on any OS or setup?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Here are the problems I can think of:

  1. If you wish to support resizing, this may be extra trouble. But you can fix the window size when the user stops dragging.

  2. On Unix desktops, tiling window managers force windows to take on certain sizes regardless of the application's requested size. (If you're not familiar, think of them as a sort of virtual multi-monitor system where each window is always “full screen” within one of the regions.) In this case, I think it would be reasonable to render with an extra black line at the edge of the viewport — don't change your shader algorithm, just render at the next smaller even size.

\$\endgroup\$
1
  • \$\begingroup\$ Yes I use glfwSetWindowSizeCallback and set the even size via glfwSetWindowSize however you have given me the idea to just render to even size irrespective of window size. Rather than a black line, render past the edges (bottom and or left) by 1 pixel (it will just be clipped) and will not mess with window managers. \$\endgroup\$
    – Blindman67
    Jun 5, 2023 at 23:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .