Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Antialiasing and Multisampling Tutorial
Text Antialiasing

Visualization Library addresses text rendering and line/polygon/points antialiasing separately. Visualization Library uses FreeType for text rendering which natively supports high quality sub-pixel antialiasing. Of course the antialiasing effect depends on the type and quality of the font used. The fonts distributed with VL (Bitstream Vera from the Gnome project) for example are excellent fonts and render high quality text. Poor fonts will always render poor text. The user does not need to enable text antialiasing, the text is always rendered antialiased, regardless of the settings discussed below.

Geometry Antialiasing

Antialiasing gometrical primitives is a totally different issue. In this case we can achieve antialiasing in two ways.

1) Smoothing.

Smoothing off Smoothing on

Enabling point, line and polygon smoothing:

ref<Effect> fx = new Effect;
fx->shader()->enable(EN_BLEND);
fx->shader()->enable(EN_POINT_SMOOTH);
fx->shader()->enable(EN_LINE_SMOOTH);
fx->shader()->enable(EN_POLYGON_SMOOTH);

Point, line and polygon smoothing requires alpha blending, for this reason we also enabled EN_BLEND. Unfortunately the fact that we are using blending makes our rendering order-dependent. That is, the order in which the primitives are drawn affects the final result. See also Transparency and Polygon Depth Sorting Tutorial for more information. You can use vl::DepthSortCallback to sort the primitives within an object but since this implies a consistent performance penalty one often accepts a few artifacts to preserve good performances. Usually this is not a big problem for smoothed lines or points, while smoothed polygons are used much more rarely in comparison.

Keep also in mind that smoothed primitives require always more computational power compared to non smoothed ones.

2) Multisampling.

Multisampling off Multisampling 8x on

When creating your OpenGL context enable multisampling. Doing this using a GUI framework supported by VL is very simple (see also Spinning Cube Tutorial):

OpenGLContextFormat format;
...
format.setMultisampleSamples(8);
format.setMultisample(true);

The code above enables 8x multisampling (if your system supports it). Note that, for example, if you require 8x and your system supports only 4x, VL automatically selects 4x multisampling. Note also that selecting the appropriate pixel format is not an OpenGL issues but is rather a GUI framework issue. For this reason you might need to search through the documentation of your GUI framework (Win32, Qt, wxWidgets etc.) in order to open a multisampling-capable OpenGL rendering context.

Multisampling is basically transparent to the application, once is it enabled, everything becomes antialiased. Note that multisampling is enabled by default. You can enable or disable multisampling using glEnable/glDisable(GL_MULTISAMPLE).

For more information on multisampling see http://www.opengl.org/registry/specs/ARB/multisample.txt