What makes my choice GLFW_SAMPLES?

What does this variable do? For example, if I set the value to 4, what does this mean?

I read the description on glfw.org (see here: GLFW Window Guide ) in the "Framebuffer Tips" section. The manual states that "GLFW_SAMPLES sets the desired number of samples used for multisampling. Zero disables multisampling. GLFW_DONT_CARE means that the application does not have preference."

I also read the description of multisampling in general (see here: Multisampling Shawn Hargreaves).

I have a general idea of ​​what multisampling means: when resizing and redrawing the image, the number of points used to redraw the image should be close enough that what we see is an accurate representation of the image. The same idea appears with the help of digital oscilloscopes - let's say you select a sinusoidal signal. If the sampling frequency is exactly the same as the frequency (f) of the wave, the area displays a constant voltage that is very different from the input signal that you hope to see. To avoid this, the Nyquist theorem tells us that we must choose at a speed of at least 2f. Therefore, I see how a problem can occur in computer graphics, but I don’t know what exactly the function

glfwWindowHint(GLFW_SAMPLES, 4); does.

+5
source share
1 answer

What does this variable do? For example, if I set it to 4, what does it mean?

GLFW_SAMPLES used to enable multisampling. So glfwWindowHint(GLFW_SAMPLES, 4) is a way to incorporate 4x MSAA into your application.

4x MSAA means that each pixel of the window buffer consists of 4 sub-samples, which means that each pixel consists of 4 pixels, so to speak. Thus, a buffer of 200x100 pixels will be 800x400 pixels.


If you need to create an additional framebuffer, which is 4 times the screen. Then, using the filter as a texture filter with GL_LINEAR as the filter, basically will achieve the same result. Note that this applies only to 4x MSAA, since GL_LINEAR only accepts 4 samples closest to the pixel in question.

When it comes to anti-aliasing, using MSAA is a really effective, but expensive solution. If you want to get a very clean and beautiful result, then this is definitely the way to go. The 4x MSAA is usually chosen as a good balance between quality and performance.

A cheaper alternative in terms of performance is to use FXAA . This is done as a post-processing step and is usually provided free of charge. The difference is that the MSAA displays a larger size and reduces the size to the desired size without losing any quality. Where, like FXAA, it simply averages the pixels as it is, basically masking the image. FXAA usually gives a really decent result.

Also, your driver will most likely enable it by default. But if it does not use, then use glEnable(GL_MULTISAMPLE) .


Finally, if you have not already done so, I highly recommend reading the LearnOpenGL Anti-Aliasing tutorial. This provides a truly detailed explanation of all this.

+7
source

Source: https://habr.com/ru/post/1265587/


All Articles