# Visualization Library

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

[Home] [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.

- Pro: supported by basically every OpenGL implementation.
- Cons: needs blending enabled; needs back to front sorting; usually you have to accept some artifacts.

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).

- Pro: virtually well supported (OpenGL 1.3 upwards); nicely and correctly multisamples everything; no blending or sorting is needed.
- Cons: slower rendering; can use a consistent amount of GPU memory to store the extra samples; antialiasing quality and support depends on the user's system capability.

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

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:28.
Permission is granted to use this page to write and publish articles regarding Visualization Library.