where is GL_MULTISAMPLE defined?

Armen Tsirunyan picture Armen Tsirunyan · Nov 17, 2010 · Viewed 12.3k times · Source

Although I have been discouraged from reading the OpenGL redbook, I am still doing it, because it is the only book designed for beginners, and tutorials and/or documentation don't quite substitute for a book although very important. So much for justifying myself :)

Now, there's an example for antialiasing using multisampling, which involved glEnable(GL_MULTISAMPLE);

I am using Qt, and I get a compile error, because GL_MULTISAMPLE is an undeclared identifier. I currently see the following reasons:

  • For some implementations, including the one that comes with Qt, GL_MULTISAMPLE is not defined.
  • It is not in GL/gl.h or GL/glu.h but rather in some other header which is not included in <QGLWidget> or does not come with Qt
  • It is obsolete/deprecated

Is one of the above reasons correct? If not, which is the reason I don't have it and how can I obtain? Thanks in advance

Answer

ʀᴏʙ picture ʀᴏʙ · Feb 23, 2012

Since you said you're using Qt's libraries then GLEW etc probably isn't necessary since Qt wraps and binds the extensions for you.

If you're using QGLWidget it's particularly easy. Check this example that ships with Qt and uses GL_MULTISAMPLE, particularly the glwidget.cpp file which defines:

#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE  0x809D
#endif

If you want to customise the FSAA samples, pass your own QGLFormat to the QGLWidget constructor eg:

QGLFormat format;
format.setDoubleBuffer(true);
format.setDepth(false);
format.setAlpha(false);
format.setSampleBuffers(true);
format.setSamples(4);
QGLWidget *glw = new QGLWidget(format);

Change format.setSamples(4) to your liking. Be sure to add glEnable(GL_MULTISAMPLE) in your paintGL() function before rendering your scene.