Multisampling

You can see that the triangle has jagged edges. That's because of the aliasing effect. You can counter it by enabling multisampling for the window, which will make OpenGL render the contents as if the screen had higher resolution and then average the result, which acts as anti-aliasing. To do that, add the following code to the constructor of the window:

QSurfaceFormat fmt = format();
fmt.setSamples(16); // multisampling set to 16
setFormat(fmt);
Note that multisampling is resource-demanding, so setting a high number of samples may cause your application to fail if your hardware or driver can't handle it. If the application doesn't work after enabling multisampling, try to lower the number of samples or just disable it.

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.